Added basic play feature for the audio buffer
This commit is contained in:
@@ -1,6 +1,7 @@
|
||||
# -*- coding: utf-8 -*-
|
||||
import widgetUtils
|
||||
import messages
|
||||
import player
|
||||
import utils
|
||||
from wxUI.tabs import home
|
||||
from pubsub import pub
|
||||
@@ -70,3 +71,13 @@ class feedBuffer(baseBuffer):
|
||||
class audioBuffer(feedBuffer):
|
||||
def create_tab(self, parent):
|
||||
self.tab = home.audioTab(parent)
|
||||
|
||||
def connect_events(self):
|
||||
widgetUtils.connect_event(self.tab.post, widgetUtils.BUTTON_PRESSED, self.post)
|
||||
widgetUtils.connect_event(self.tab.play, widgetUtils.BUTTON_PRESSED, self.play_audio)
|
||||
|
||||
def play_audio(self, *args, **kwargs):
|
||||
selected = self.tab.list.get_selected()
|
||||
player.player.play(self.session.db[self.name]["items"][selected]["url"])
|
||||
|
||||
player.setup()
|
@@ -1,11 +1,11 @@
|
||||
# -*- coding: utf-8 -*-
|
||||
import widgetUtils
|
||||
import messages
|
||||
from wxUI import (mainWindow)
|
||||
import buffers
|
||||
from pubsub import pub
|
||||
from mysc.repeating_timer import RepeatingTimer
|
||||
from sessionmanager import session
|
||||
from wxUI import (mainWindow)
|
||||
|
||||
class Controller(object):
|
||||
|
||||
|
46
src/controller/player.py
Normal file
46
src/controller/player.py
Normal file
@@ -0,0 +1,46 @@
|
||||
# -*- coding: utf-8 -*-
|
||||
import sound_lib
|
||||
from sound_lib.output import Output
|
||||
from sound_lib.stream import URLStream
|
||||
|
||||
player = None
|
||||
|
||||
def setup():
|
||||
global player
|
||||
if player == None:
|
||||
player = audioPlayer()
|
||||
|
||||
class audioPlayer(object):
|
||||
|
||||
def __init__(self):
|
||||
Output()
|
||||
self.is_playing = False
|
||||
self.stream = None
|
||||
self.vol = 100
|
||||
|
||||
def play(self, url):
|
||||
if self.stream != None and self.stream.is_playing == True:
|
||||
self.stream.stop()
|
||||
self.stream = URLStream(url=url)
|
||||
self.stream.volume = self.vol/100.0
|
||||
self.stream.play()
|
||||
|
||||
def stop(self):
|
||||
if self.stream != None and self.stream.is_playing == True:
|
||||
self.stream.stop()
|
||||
|
||||
def pause(self):
|
||||
if self.stream != None and self.stream.is_playing == True:
|
||||
self.stream.pause()
|
||||
|
||||
@property
|
||||
def volume(self):
|
||||
if self.stream != None:
|
||||
return self.vol
|
||||
|
||||
@volume.setter
|
||||
def volume(self, vol):
|
||||
self.vol = vol
|
||||
if self.stream != None:
|
||||
self.stream.volume = vol/100.0
|
||||
|
Reference in New Issue
Block a user