Switched from sound_lib to libvlc
This commit is contained in:
parent
8c95d54305
commit
38a9829ca9
@ -84,12 +84,10 @@ class Controller(object):
|
|||||||
ev.Skip()
|
ev.Skip()
|
||||||
|
|
||||||
def on_play_pause(self, *args, **kwargs):
|
def on_play_pause(self, *args, **kwargs):
|
||||||
if player.player.check_is_playing() != False:
|
if player.player.player.is_playing() == 1:
|
||||||
return player.player.pause()
|
return player.player.pause()
|
||||||
elif player.player.stream != None:
|
|
||||||
player.player.stream.play()
|
|
||||||
else:
|
else:
|
||||||
self.on_play()
|
player.player.player.play()
|
||||||
|
|
||||||
def on_next(self, *args, **kwargs):
|
def on_next(self, *args, **kwargs):
|
||||||
return utils.call_threaded(player.player.next)
|
return utils.call_threaded(player.player.next)
|
||||||
|
@ -1,10 +1,7 @@
|
|||||||
# -*- coding: utf-8 -*-
|
# -*- coding: utf-8 -*-
|
||||||
import random
|
import random
|
||||||
import sound_lib
|
import vlc
|
||||||
import logging
|
import logging
|
||||||
from sound_lib.stream import URLStream
|
|
||||||
from sound_lib.main import BassError
|
|
||||||
from sound_lib.output import Output
|
|
||||||
from pubsub import pub
|
from pubsub import pub
|
||||||
from utils import RepeatingTimer
|
from utils import RepeatingTimer
|
||||||
|
|
||||||
@ -14,44 +11,38 @@ log = logging.getLogger("player")
|
|||||||
def setup():
|
def setup():
|
||||||
global player
|
global player
|
||||||
if player == None:
|
if player == None:
|
||||||
Output()
|
|
||||||
player = audioPlayer()
|
player = audioPlayer()
|
||||||
|
|
||||||
class audioPlayer(object):
|
class audioPlayer(object):
|
||||||
|
|
||||||
def __init__(self):
|
def __init__(self):
|
||||||
self.is_playing = False
|
self.is_playing = False
|
||||||
self.stream = None
|
|
||||||
self.vol = 50
|
self.vol = 50
|
||||||
self.is_working = False
|
self.is_working = False
|
||||||
self.queue = []
|
self.queue = []
|
||||||
self.stopped = True
|
self.stopped = True
|
||||||
self.queue_pos = 0
|
self.queue_pos = 0
|
||||||
self.shuffle = False
|
self.shuffle = False
|
||||||
|
self.instance = vlc.Instance()
|
||||||
|
self.player = self.instance.media_player_new()
|
||||||
|
|
||||||
def play(self, item):
|
def play(self, item):
|
||||||
if self.stream != None and self.stream.is_playing == True:
|
|
||||||
try:
|
|
||||||
self.stream.stop()
|
|
||||||
except BassError:
|
|
||||||
log.exception("error when stopping the file")
|
|
||||||
self.stopped = True
|
self.stopped = True
|
||||||
# Make sure there are no other sounds trying to be played.
|
# Make sure 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
|
||||||
if item.download_url == "":
|
if item.download_url == "":
|
||||||
item.get_download_url()
|
item.get_download_url()
|
||||||
try:
|
self.stream_new = self.instance.media_new(item.download_url)
|
||||||
self.stream = URLStream(url=item.download_url)
|
self.player.set_media(self.stream_new)
|
||||||
except BassError as e:
|
if self.player.play() == -1:
|
||||||
log.debug("Error when playing the file {0}".format(item.title,))
|
log.debug("Error when playing the file {0}".format(item.title,))
|
||||||
pub.sendMessage("change_status", status=_("Error playing {0}. {1}.").format(item.title, e.description))
|
pub.sendMessage("change_status", status=_("Error playing {0}. {1}.").format(item.title, e.description))
|
||||||
self.stopped = True
|
self.stopped = True
|
||||||
self.is_working = False
|
self.is_working = False
|
||||||
self.next()
|
self.next()
|
||||||
return
|
return
|
||||||
self.stream.volume = self.vol/100.0
|
self.player.audio_set_volume(self.vol)
|
||||||
self.stream.play()
|
|
||||||
pub.sendMessage("change_status", status=_("Playing {0}.").format(item.title))
|
pub.sendMessage("change_status", status=_("Playing {0}.").format(item.title))
|
||||||
self.stopped = False
|
self.stopped = False
|
||||||
self.is_working = False
|
self.is_working = False
|
||||||
@ -79,33 +70,25 @@ class audioPlayer(object):
|
|||||||
self.play(self.queue[self.queue_pos])
|
self.play(self.queue[self.queue_pos])
|
||||||
|
|
||||||
def stop(self):
|
def stop(self):
|
||||||
if self.stream != None and self.stream.is_playing == True:
|
self.player.stop()
|
||||||
self.stream.stop()
|
|
||||||
self.stopped = True
|
self.stopped = True
|
||||||
|
|
||||||
def pause(self):
|
def pause(self):
|
||||||
if self.stream != None:
|
self.player.pause()
|
||||||
if self.stream.is_playing == True:
|
if self.stopped == True:
|
||||||
self.stream.pause()
|
|
||||||
self.stopped = True
|
|
||||||
else:
|
|
||||||
try:
|
|
||||||
self.stream.play()
|
|
||||||
self.stopped = False
|
self.stopped = False
|
||||||
except BassError:
|
else:
|
||||||
pass
|
self.stopped = True
|
||||||
|
|
||||||
@property
|
@property
|
||||||
def volume(self):
|
def volume(self):
|
||||||
# if self.stream != None:
|
|
||||||
return self.vol
|
return self.vol
|
||||||
|
|
||||||
@volume.setter
|
@volume.setter
|
||||||
def volume(self, vol):
|
def volume(self, vol):
|
||||||
if vol <= 100 and vol >= 0:
|
if vol <= 100 and vol >= 0:
|
||||||
self.vol = vol
|
self.vol = vol
|
||||||
if self.stream != None:
|
self.player.audio_set_volume(self.vol)
|
||||||
self.stream.volume = self.vol/100.0
|
|
||||||
|
|
||||||
def play_all(self, list_of_items, playing=0, shuffle=False):
|
def play_all(self, list_of_items, playing=0, shuffle=False):
|
||||||
if list_of_items != self.queue:
|
if list_of_items != self.queue:
|
||||||
@ -118,16 +101,7 @@ class audioPlayer(object):
|
|||||||
self.worker.start()
|
self.worker.start()
|
||||||
|
|
||||||
def player_function(self):
|
def player_function(self):
|
||||||
if self.stream != None and self.stream.is_playing == False and self.stopped == False and len(self.stream) == self.stream.position:
|
if self.player.is_playing() == 0 and self.stopped == False:
|
||||||
if len(self.queue) == 0:
|
if len(self.queue) == 0:
|
||||||
return
|
return
|
||||||
self.next()
|
self.next()
|
||||||
|
|
||||||
def check_is_playing(self):
|
|
||||||
if self.stream == None:
|
|
||||||
return False
|
|
||||||
if self.stream != None and self.stream.is_playing == False:
|
|
||||||
return False
|
|
||||||
else:
|
|
||||||
return True
|
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user