Skip to content
This repository has been archived by the owner on Nov 9, 2019. It is now read-only.

Commit

Permalink
Add very slow pause/resume/seek +- 10s
Browse files Browse the repository at this point in the history
  • Loading branch information
alexpdp7 committed Aug 19, 2018
1 parent 981ab69 commit a95b46c
Show file tree
Hide file tree
Showing 3 changed files with 34 additions and 4 deletions.
26 changes: 22 additions & 4 deletions pyccw/main/services.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,17 +13,35 @@
def play(mediasource, path, file):
url = spawn_server(mediasource.get_sub_path(path), file)
content_type = 'video/{0}'.format(file.split('.')[-1])
chromecasts = get_chromecasts()
assert len(chromecasts) == 1
chromecast = chromecasts[0]
chromecast.play_media(url, content_type)
get_chromecast().play_media(url, content_type)


def pause():
get_chromecast().media_controller.pause()


def resume():
get_chromecast().media_controller.play()


def seek(delta):
chromecast = get_chromecast()
chromecast.media_controller.seek(chromecast.media_controller.status.current_time + delta)


def get_chromecasts():
chromecasts = pychromecast.get_chromecasts()
return [cc for cc in chromecasts if cc.model_name not in EXCLUDED_MODELS]


def get_chromecast():
chromecasts = get_chromecasts()
assert len(chromecasts) == 1
chromecast = chromecasts[0]
chromecast.media_controller.block_until_active()
return chromecast


def get_hostname():
# return socket.gethostname() # Chromecasts use Google's DNS, so this doesn't work
return settings.CAST_HOST
Expand Down
4 changes: 4 additions & 0 deletions pyccw/main/templates/main/cast.html
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,10 @@
<form method="POST">
{% csrf_token %}
<button name="action" value="play">Play</button>
<button name="action" value="pause">Pause</button>
<button name="action" value="resume">Resume</button>
<button name="action" value="backward_10">Backward 10s</button>
<button name="action" value="forward_10">Forward 10s</button>
</form>
</body>
</html>
8 changes: 8 additions & 0 deletions pyccw/main/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,14 @@ def cast(request, mediasource, path, file):
action = request.POST['action']
if action == 'play':
services.play(ms, path, file)
if action == 'pause':
services.pause()
if action == 'resume':
services.resume()
if action == 'backward_10':
services.seek(-10)
if action == 'forward_10':
services.seek(10)

return shortcuts.render(request, 'main/cast.html', {
'media_source': ms,
Expand Down

0 comments on commit a95b46c

Please sign in to comment.