Skip to content

Instantly share code, notes, and snippets.

@SuitLollipop
Last active July 4, 2018 09:58
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save SuitLollipop/b693cefcead7484834551b388bad2d53 to your computer and use it in GitHub Desktop.
Save SuitLollipop/b693cefcead7484834551b388bad2d53 to your computer and use it in GitHub Desktop.
Hooking up the Tizen's av play video object to Suitest requires a few extra lines of code. This is due to the object's architecture that does not allow multiple independent listeners. For more information check: https://suite.st/docs/testing/test-subjects/video-subject/
function init() {
/**
* Suitest-specific constants that define video play state
* @type {Object}
*/
var suitestStates = {
STOPPED: 'stopped',
PLAYING: 'playing',
PAUSED: 'paused',
CONNECTING: 'connecting',
BUFFERING: 'buffering',
FINISHED: 'finished',
ERROR: 'error'
};
/**
* Video element
* @type {string}
*/
var el = document.getElementById('av-player');
/**
* Video URL to play
* @type {string}
*/
var url = 'http://download.blender.org/peach/bigbuckbunny_movies/BigBuckBunny_320x180.mp4';
/**
* A variable to store current video play state based on AVPlay callbacks
* @type {string}
*/
var state = suitestStates.STOPPED;
/**
* AVPlay listener callbacks
* @type {Object}
*/
var listener = {
onbufferingstart: function() {
state = suitestStates.BUFFERING;
},
onstreamcompleted: function() {
state = suitestStates.FINISHED;
},
onerror: function(e) {
state = suitestStates.ERROR;
}
};
/**
* Map AVPlay state to Suitest state,
* extend it with more precise data, received from listener callbacks
* @param avState
* @returns {string}
*/
function mapState(avState) {
switch (avState) {
case 'PLAYING':
return suitestStates.PLAYING;
case 'PAUSED':
return suitestStates.PAUSED;
case 'NONE':
case 'IDLE':
case 'READY':
default:
// otherwise return state, recorded by listener callbacks
return state;
}
}
// Set-up Suitest custom video player adapter
var removeSuitestAdapter = suitest.setVideoAdapter(function(videoElement) {
return {
// We ignore "videoElement" input, as in AVPlay
// it's an object element
element: el,
// Get current video duration
length: webapis.avplay.getDuration(),
// Get current video position
pos: webapis.avplay.getCurrentTime(),
// URL, that is being played
url: url,
// Current video state, mapped to one Suitest values
state: mapState(webapis.avplay.getState())
};
});
setTimeout(function() {
// Set-up and play video with AVPlay platform
webapis.avplay.open(url);
webapis.avplay.setListener(listener);
webapis.avplay.setDisplayRect(5, 5, 640, 360);
webapis.avplay.prepare();
webapis.avplay.play();
}, 3000);
}
window.onload = init;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment