Skip to content

Instantly share code, notes, and snippets.

@rtmalone
Created January 13, 2016 17:44
Show Gist options
  • Select an option

  • Save rtmalone/2ff66b357f4a23f2e9a2 to your computer and use it in GitHub Desktop.

Select an option

Save rtmalone/2ff66b357f4a23f2e9a2 to your computer and use it in GitHub Desktop.
rabble mobile player
'use strict';
angular.module('rabbleClientApp')
.directive('htmlplayer', function ($rootScope, $state, $timeout, $detection, PlayerUtilsService, constants, LogService, ListensService, SocketUtilsService, MessageService) {
var directive = {
restrict: 'E',
transclude: true,
templateUrl: '/views/templates/htmlplayer.html',
scope :{
broadcast: '=ngModel'
},
link: function (scope) {
scope.ios = $detection.isiOS();
scope.android = $detection.isAndroid();
scope.$on('broadcast-play-' + $rootScope.currentBroadcast._id, function(){
console.log('broadcast-play');
if (!_init) {
// increment listens on broadcast
ListensService.create({broadcast: $rootScope.currentBroadcast._id}, function(){
// yada yada
}, function(err){
MessageService.translateErrorMessage(err);
});
_init = true;
console.log('helloe');
}
});
// Unsubscription
scope.$on('$destroy', function destroy() {
if (scope.broadcast) {
SocketUtilsService.unnotifyBroadcastInterrupt(scope.broadcast);
}
});
scope.initiate = function() {
$rootScope.showPlayer = true;
scope.initiated = !scope.initiated;
soundManager.togglePause('bcastSound');
console.log('play?');
scope.sm2State = 'playing';
scope.sm2Render = true;
$timeout(function() {
scope.$apply();
});
// ListensService.create({broadcast: scope.broadcast._id}, function() {
// // Nothing to do...
// }, function(err) {
// MessageService.translateErrorMessage(err);
// });
};
scope.uninitiate = function() {
scope.initiated = false;
};
scope.close = function() {
SocketUtilsService.unnotifyBroadcastInterrupt(scope.broadcast);
scope.broadcast = undefined;
PlayerUtilsService.resetUi();
};
scope.closeMobileHelp = function(redirectToLogin) {
$rootScope.dismissMobilePlayerHelp = true;
if (redirectToLogin) {
$state.go('login');
}
};
var _setupStream = function() {
LogService.info('RELOADING HTML PLAYER!');
scope.initiated = false;
scope.broadcast = $rootScope.currentBroadcast;
// Listen for interruption events...
SocketUtilsService.notifyBroadcastInterrupt(scope.broadcast);
scope.$on('broadcast-interrupt-' + scope.broadcast._id, function() {
MessageService.addWarning('This broadcaster may be experiencing problems.');
$timeout(function() {
scope.$apply();
});
});
if (scope.broadcast) {
if (scope.broadcast.current) {
scope.url = scope.broadcast.cdn + '/hls/' + scope.broadcast.stream + '.m3u8';
} else if (scope.broadcast.archive) {
// scope.url = constants.httpRecordingUri + '/' + scope.broadcast.recording + '/index.m3u8';
scope.url = 'http://www.stephaniequinn.com/Music/Commercial%20DEMO%20-%2011.mp3';
} else {
scope.url = undefined;
}
scope.stream = {id: scope.broadcast._id, url: scope.url};
}
_setupSm2Player();
};
var _setupSm2Player = function(){
soundManager.setup({
url: '/sm2/swf/',
preferFlash: false,
onready: function() {
soundManager.createSound({
id: 'bcastSound',
// url: 'http://www.stephaniequinn.com/Music/Commercial%20DEMO%20-%2011.mp3',
url: scope.url,
autoLoad: true,
autoplay: true
});
}
});
// initiate();
scope.initiate();
};
// with this var I am tracking the need to increment a play or not.
var _init = false;
_setupStream();
// End LINK attr of directive
}
};
return directive;
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment