Skip to content

Instantly share code, notes, and snippets.

@gauntface
Created February 19, 2013 16:03
Show Gist options
  • Select an option

  • Save gauntface/4987180 to your computer and use it in GitHub Desktop.

Select an option

Save gauntface/4987180 to your computer and use it in GitHub Desktop.
Sample of the NativeVideoPlayerController class
NativeVideoPlayerController.prototype = new GenericVideoPlayerController();
/**
* This handles the playback through a native VideoView rather than a HTML5
* video tag
*
* @constructor
* @augments GenericVideoPlayerController
*/
function NativeVideoPlayerController() {
// This player requires a transparent body
$('body').css('background-color', 'transparent');
var autoPlay = true;
/**
* Check is the video player is set to auto play
*/
this.isAutoPlay = function () {
return autoPlay;
};
}
/**
* When a url has changed on the video this method is called to handle it
* @function
* @param {String} url
*/
NativeVideoPlayerController.prototype.onVideoUrlChange = function (url) {
// Launch into native
var autoPlayString = '';
if(this.isAutoPlay()) {
autoPlayString = ';'+this.isAutoPlay()+';';
}
this.handleAction('nativewebsample://ACTION_LOAD_VIDEO;' + url + autoPlayString);
};
/**
* Method to handle a play / pause toggle
* @function
*/
NativeVideoPlayerController.prototype.playPause = function () {
this.handleAction('nativewebsample://ACTION_PLAY_PAUSE_VIDEO;');
};
/**
* Rewind the application but the specified number of seconds defined in the
* GenericVideoPlayerController
* @function
*/
NativeVideoPlayerController.prototype.rewind = function () {
this.handleAction('nativewebsample://ACTION_REWIND_VIDEO;'+this.getSkipSpeedSeconds()+';');
};
/**
* Fast forward the application but the specified number of seconds defined in the
* GenericVideoPlayerController
* @function
*/
NativeVideoPlayerController.prototype.fastForward = function () {
this.handleAction('nativewebsample://ACTION_FASTFORWARD_VIDEO;'+this.getSkipSpeedSeconds()+';');
};
/**
* This method handles an action which needs to be handled by the native
* application.
*
* This class does not perform any filtering / parsing of the URI to ensure
* it is valid, it relies on the Native application to handle the URI's
* appropriately.
*
* @function
* @param {String} action The action to pass to the native app
*/
NativeVideoPlayerController.prototype.handleAction = function (action) {
if(typeof AppInterface == 'undefined' || !AppInterface) {
console.log('The AppInterface object has not been defined [Have you set up your app client to inject this?]');
return;
}
// App Interface is set by the Android client
AppInterface.handleURI(action);
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment