Fixed an issue when playing a song in Python 2

This commit is contained in:
Manuel Cortez 2019-01-01 20:04:30 -06:00
parent 53d5a09fb4
commit 8dcee29952

View File

@ -1,5 +1,6 @@
# -*- coding: utf-8 -*- # -*- coding: utf-8 -*-
from __future__ import unicode_literals from __future__ import unicode_literals
import sys
import random import random
import output import output
import sound_lib import sound_lib
@ -43,8 +44,13 @@ class audioPlayer(object):
# Make sure that there are no other sounds trying to be played. # Make sure that there are no other sounds trying to be played.
if self.is_working == False: if self.is_working == False:
self.is_working = True self.is_working = True
# Let's encode the URL as bytes if on Python 3
if sys.version[0] == "3":
url_ = bytes(url["url"], "utf-8")
else:
url_ = url["url"]
try: try:
self.stream = URLStream(url=bytes(url["url"], "utf-8")) self.stream = URLStream(url=url_)
except BassError: except BassError:
log.debug("Error when playing the file %r") % (url,) log.debug("Error when playing the file %r") % (url,)
return return