()
| 946 | 'sprites':['png', 'jpg', 'bmp']} |
| 947 | |
| 948 | def test_music(): |
| 949 | try: |
| 950 | import pyglet |
| 951 | if pyglet.version >= '1.4': |
| 952 | from pyglet.media import have_ffmpeg |
| 953 | pyglet.media.have_avbin = have_ffmpeg() |
| 954 | if not pyglet.media.have_avbin: |
| 955 | cfg.USE_MUSIC = False |
| 956 | else: |
| 957 | try: |
| 958 | from pyglet.media import avbin |
| 959 | except Exception as e: |
| 960 | debug_msg(e) |
| 961 | pyglet.lib.load_library('avbin') |
| 962 | if pyglet.version >= '1.2': # temporary workaround for defect in pyglet svn 2445 |
| 963 | pyglet.media.have_avbin = True |
| 964 | |
| 965 | # On Windows with Data Execution Protection enabled (on by default on Vista), |
| 966 | # an exception will be raised when use of avbin is attempted: |
| 967 | # WindowsError: exception: access violation writing [ADDRESS] |
| 968 | # The file doesn't need to be in a avbin-specific format, |
| 969 | # since pyglet will use avbin over riff whenever it's detected. |
| 970 | # Let's find an audio file and try to load it to see if avbin works. |
| 971 | opj = os.path.join |
| 972 | opj = os.path.join |
| 973 | def look_for_music(path): |
| 974 | files = [p for p in os.listdir(path) if not p.startswith('.') and not os.path.isdir(opj(path, p))] |
| 975 | for f in files: |
| 976 | ext = f.lower()[-3:] |
| 977 | if ext in ['wav', 'ogg', 'mp3', 'aac', 'mp2', 'ac3', 'm4a'] and not ext in ('wav'): |
| 978 | return [opj(path, f)] |
| 979 | dirs = [opj(path, p) for p in os.listdir(path) if not p.startswith('.') and os.path.isdir(opj(path, p))] |
| 980 | results = [] |
| 981 | for d in dirs: |
| 982 | results.extend(look_for_music(d)) |
| 983 | if results: return results |
| 984 | return results |
| 985 | music_file = look_for_music(res_path) |
| 986 | if music_file: |
| 987 | # The first time we load a file should trigger the exception |
| 988 | music_file = music_file[0] |
| 989 | loaded_music = pyglet.media.load(music_file, streaming=False) |
| 990 | del loaded_music |
| 991 | else: |
| 992 | cfg.USE_MUSIC = False |
| 993 | |
| 994 | except ImportError as e: |
| 995 | debug_msg(e) |
| 996 | cfg.USE_MUSIC = False |
| 997 | if pyglet.version >= '1.2': |
| 998 | pyglet.media.have_avbin = False |
| 999 | print( _('AVBin not detected. Music disabled.')) |
| 1000 | print( _('Download AVBin from: https://avbin.github.io')) |
| 1001 | |
| 1002 | except Exception as e: # WindowsError |
| 1003 | debug_msg(e) |
| 1004 | cfg.USE_MUSIC = False |
| 1005 | pyglet.media.have_avbin = False |
no test coverage detected