Skip to content

Commit

Permalink
Added pygame 1.9.4 compatibility
Browse files Browse the repository at this point in the history
  • Loading branch information
ppizarror committed Jul 31, 2019
1 parent c9eeb7c commit 1cdcf4f
Show file tree
Hide file tree
Showing 3 changed files with 30 additions and 7 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
<a href="https://ppizarror.com"><img alt="@ppizarror" src="https://img.shields.io/badge/author-Pablo%20Pizarro%20R.-lightgray.svg" /></a>
<a href="https://opensource.org/licenses/MIT/"><img alt="License MIT" src="https://img.shields.io/badge/license-MIT-blue.svg" /></a>
<a href="https://www.python.org/downloads/"><img alt="Python 2.7+/3.4+" src="https://img.shields.io/badge/python-2.7+ / 3.4+-red.svg" /></a>
<a href="https://www.pygame.org/"><img alt="Pygame 1.9.5+" src="https://img.shields.io/badge/pygame-1.9.5+-orange.svg" /></a>
<a href="https://www.pygame.org/"><img alt="Pygame 1.9.4+" src="https://img.shields.io/badge/pygame-1.9.4+-orange.svg" /></a>
<a href="https://pypi.org/project/pygame-menu/"><img alt="PyPi package" src="https://badge.fury.io/py/pygame-menu.svg" /></a>
<br>
<a href="https://codecov.io/gh/ppizarror/pygame-menu"><img src="https://codecov.io/gh/ppizarror/pygame-menu/branch/master/graph/badge.svg" /></a>
Expand Down
33 changes: 28 additions & 5 deletions pygameMenu/sound.py
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@
# Import pygame and base audio mixer
from pygame import error as _pygame_error
from pygame import mixer as _mixer
from pygame import vernum as _pygame_version

try: # pygame<2.0.0 compatibility
from pygame import AUDIO_ALLOW_CHANNELS_CHANGE as _AUDIO_ALLOW_CHANNELS_CHANGE
Expand Down Expand Up @@ -119,11 +120,33 @@ def __init__(self,

# Initialize sounds if not initialized
if _mixer.get_init() is None or force_init:
_mixer.init(frequency=frequency,
size=size,
channels=channels,
buffer=buffer,
devicename=devicename)

# Check pygame version
version_major, _, version_minor = _pygame_version

# <= 1.9.4
if version_major == 1 and version_minor <= 4:
_mixer.init(frequency=frequency,
size=size,
channels=channels,
buffer=buffer)

# <2.0.0 & >= 1.9.5
elif version_major == 1 and version_minor > 4:
_mixer.init(frequency=frequency,
size=size,
channels=channels,
buffer=buffer,
devicename=devicename)

# >= 2.0.0
elif version_major > 1:
_mixer.init(frequency=frequency,
size=size,
channels=channels,
buffer=buffer,
devicename=devicename,
allowedchanges=allowedchanges)

# Channel where a sound is played
self._channel = None # type: _mixer.ChannelType
Expand Down
2 changes: 1 addition & 1 deletion requirements.txt
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
pygame>=1.9.5
pygame>=1.9.4
pyperclip

0 comments on commit 1cdcf4f

Please sign in to comment.