Skip to content

Instantly share code, notes, and snippets.

@satsalou
Created October 6, 2015 09:33
Show Gist options
  • Save satsalou/49378cab36aa054c5bd5 to your computer and use it in GitHub Desktop.
Save satsalou/49378cab36aa054c5bd5 to your computer and use it in GitHub Desktop.
.controller('StreamController', function($interval, streamService) {
var isPlaying = false;
var stream;
var timer;
var vm = angular.extend(this, {
togglePlay: togglePlay,
isPlaying: isPlaying,
info: null
});
// *********************************************************************
function togglePlay() {
if (vm.isPlaying) {
pause();
} else {
play();
}
vm.isPlaying = isPlaying = !isPlaying;
}
function play() {
if (window.Stream) {
stream = new window.Stream('http://198.100.125.242:80/');
// Play audio
stream.play();
}
getStreamInfo();
timer = $interval(function() {
getStreamInfo();
}, 5000);
}
function pause() {
vm.info = null;
$interval.cancel(timer);
if (!stream) {
return;
}
stream.stop();
}
function getStreamInfo() {
streamService.getStreamInfo().then(function(info) {
vm.info = info;
}, function() {
vm.info = null;
});
}
})
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment