Last active
August 29, 2015 14:17
-
-
Save spartanatreyu/dd7bc772a5ed85ff512a to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* jshint devel: true */ | |
/* global angular */ | |
'use strict'; | |
/* | |
Requres: https://github.com/dawsonloudon/VideoPlayer | |
Usage: <videoplayer src="videofile"></videoplayer> | |
Don't put ".mp4" or ".webm" in the src atr above | |
*/ | |
angular.module('videoplayer-module', []) | |
.directive('videoplayer', ['$timeout', function($timeout) | |
{ | |
return { | |
restrict: 'E', | |
scope: | |
{ | |
src:'@' | |
}, | |
template: function() | |
{ | |
//if browser | |
if (window.cordova === undefined) | |
{ | |
return '<video controls autoplay width="320" height="180" alt="loading"/>'; | |
} | |
else if (window.cordova.platformId == 'android') | |
{ | |
return '<img src="styles/posterframe.jpg" width="320" height="180" alt="loading" />'; | |
} | |
//else if (window.cordova.platformId == 'ios') | |
else | |
{ | |
return '<video controls poster="styles/posterframe.jpg" width="320" height="180" alt="loading" />'; | |
} | |
}, | |
//link: function(scope, element, attrs) | |
link: function(scope, element) | |
{ | |
//if browser, use webm | |
if(window.cordova === undefined) | |
{ | |
element.find('video').attr('src', 'videos/' + scope.src +'.webm'); | |
//element.find('video').attr('src', 'videos/' + scope.src +'.mp4'); | |
} | |
if(window.cordova !== undefined && window.cordova.platformId == 'android') | |
{ | |
element.find('img').attr('onclick', 'VideoPlayer.play("file:///android_asset/www/videos/' + scope.src + '.webm"); '); | |
} | |
if(window.cordova !== undefined && window.cordova.platformId == 'ios') | |
{ | |
//If ios, set video's src once any other video elements are moved. | |
// | |
//ios's webview uses the ios mediaplayer, so only one video element | |
//at a time can be loaded and playing. | |
$timeout(function() | |
{ | |
element.find('b').text('ios video player: playing'); | |
element.find('video').attr('src', 'videos/' + scope.src +'.mp4'); | |
(element.find('video')[0]).play(); | |
}, 1000); | |
} | |
}, | |
controller: 'videoplayer-controller', | |
controllerAs: 'ctrl' | |
}; | |
}]) | |
.controller('videoplayer-controller', function() | |
{ | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment