0

This is my code https://raw.githubusercontent.com/T-Dynamos/Python-Games/master/Connected/main.py

Here's repo https://github.com/T-Dynamos/Python-Games/tree/master/Connected

This is logcat error:

2022-05-15 22:25:30.762 7724 7748 com.pyguru.connected I python : pygame.error: Unable to open file '/data/data/com.pyguru.connected/files/app/Sounds/flip.mp3'

Here's the fix i tried but not worked

def fileR(filename):


    return os.path.join(os.path.dirname(os.path.abspath(__file__)),filename)

After this function

flip_fx = pygame.mixer.Sound(fileR('Sounds/flip.mp3'))

After adding

import os

try:
    print(os.listdir("/data/data/com.pyguru.connected/files/app/Sounds/"))
    print(os.path.exists("/data/data/com.pyguru.connected/files/app/Sounds/flip.mp3"))
except Exception as e:
    print(str(e))

To code i got this

2022-05-15 23:22:31.687 29920 29942 com.pyguru.connected I python : ['bgm.mp3', 'dead.mp3', 'flip.mp3', 'point.mp3', 'score_page.mp3']
2022-05-15 23:22:31.688 29920 29942 com.pyguru.connected I python : True
T-Dynamos
  • 9
  • 3
  • first you could check if you really have file `/data/data/com.pyguru.connected/files/app/Sounds/flip.mp3` on androig- ie, using `os.path.exists("/data/data/com.pyguru.connected/files/app/Sounds/flip.mp3")` or checking all files in folder `os.listdir("/data/data/com.pyguru.connected/files/app/Sounds/")`. – furas May 15 '22 at 17:21
  • You could also check if code works with other formats - ie. .wav - because in PyGame doc [music](https://www.pygame.org/docs/ref/music.html) you can see `"On older pygame versions, MP3 support was limited under Mac and Linux. This changed in pygame v2.0.2 which got improved MP3 support. Consider using OGG file format for music as that can give slightly better compression than MP3 in most cases.` – furas May 15 '22 at 17:21
  • ```import os try: print(os.listdir("/data/data/com.pyguru.connected/files/app/Sounds/")) print(os.path.exists("/data/data/com.pyguru.connected/files/app/Sounds/flip.mp3")) except Exception as e: print(str(e))``` i am rebuilding with these lines now – T-Dynamos May 15 '22 at 17:27
  • Please see i edited the answer and i got this https://i.stack.imgur.com/bSYcF.jpg – T-Dynamos May 15 '22 at 17:58
  • now you can check if code works with `.wav` or `.ogg` - maybe PyGame on Android can't work with `.mp3` – furas May 15 '22 at 18:41
  • No that's not the matter its unable to open any file – T-Dynamos May 15 '22 at 19:07

0 Answers0