don't switch to null src
This commit is contained in:
parent
802c364525
commit
2445bd1e83
20
radio.py
20
radio.py
@ -1,7 +1,6 @@
|
|||||||
import downloader
|
import downloader
|
||||||
import uploader
|
import uploader
|
||||||
import transcoder
|
import transcoder
|
||||||
import nullsrc
|
|
||||||
from time import sleep
|
from time import sleep
|
||||||
from flask import Flask, request
|
from flask import Flask, request
|
||||||
from queue import Queue
|
from queue import Queue
|
||||||
@ -14,33 +13,21 @@ class Radio(object):
|
|||||||
self.transcoder = None
|
self.transcoder = None
|
||||||
self.uploader = uploader.Uploader()
|
self.uploader = uploader.Uploader()
|
||||||
self.playingUrl = None
|
self.playingUrl = None
|
||||||
self.nullsrc = False
|
|
||||||
self.queue = Queue()
|
self.queue = Queue()
|
||||||
|
|
||||||
# plays the next song in the queue
|
# plays the next song in the queue
|
||||||
def play(self):
|
def play(self):
|
||||||
self.stopPlaying()
|
|
||||||
self.nullsrc = False
|
|
||||||
self.playingUrl = self.queue.get()
|
self.playingUrl = self.queue.get()
|
||||||
self.downloader = downloader.Downloader(self.playingUrl, self.downloadFinished)
|
self.downloader = downloader.Downloader(self.playingUrl, self.downloadFinished)
|
||||||
self.transcoder = transcoder.Transcoder(self.downloader)
|
self.transcoder = transcoder.Transcoder(self.downloader)
|
||||||
self.uploader.setUpstream(self.transcoder)
|
self.uploader.setUpstream(self.transcoder)
|
||||||
|
|
||||||
def playNullSrc(self):
|
|
||||||
self.stopPlaying()
|
|
||||||
self.nullsrc = True
|
|
||||||
self.playingUrl = None
|
|
||||||
self.downloader = nullsrc.NullSrc()
|
|
||||||
self.transcoder = transcoder.Transcoder(self.downloader)
|
|
||||||
self.uploader.setUpstream(self.transcoder)
|
|
||||||
|
|
||||||
def isPlaying(self):
|
def isPlaying(self):
|
||||||
return not self.playingUrl is None
|
return not self.playingUrl is None
|
||||||
|
|
||||||
# blocks the caller until the uploader and trancoder recieve no more data
|
# blocks the caller until the uploader and trancoder recieve no more data
|
||||||
# if this is a livestream, the end might never come!
|
# if this is a livestream, the end might never come!
|
||||||
def blockUntilDonePlaying(self):
|
def blockUntilDonePlaying(self):
|
||||||
if not self.nullsrc:
|
|
||||||
self.transcoder.listener.blockUntilEmpty()
|
self.transcoder.listener.blockUntilEmpty()
|
||||||
self.uploader.listener.blockUntilEmpty()
|
self.uploader.listener.blockUntilEmpty()
|
||||||
|
|
||||||
@ -49,17 +36,12 @@ class Radio(object):
|
|||||||
self.queue.put(url)
|
self.queue.put(url)
|
||||||
|
|
||||||
def playIfSongAvailable(self):
|
def playIfSongAvailable(self):
|
||||||
if not self.isPlaying():
|
if not self.isPlaying() and not self.queue.empty():
|
||||||
if self.queue.empty():
|
|
||||||
self.playNullSrc()
|
|
||||||
else:
|
|
||||||
self.play()
|
self.play()
|
||||||
|
|
||||||
# stops playing immediately and cleans up
|
# stops playing immediately and cleans up
|
||||||
def stopPlaying(self):
|
def stopPlaying(self):
|
||||||
if not self.downloader is None:
|
|
||||||
self.downloader.stop()
|
self.downloader.stop()
|
||||||
if not self.transcoder is None:
|
|
||||||
self.transcoder.stop()
|
self.transcoder.stop()
|
||||||
self.playingUrl = None
|
self.playingUrl = None
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user