Skip to content

Instantly share code, notes, and snippets.

@mikelopez
Created October 31, 2012 19:09
Show Gist options
  • Save mikelopez/3989173 to your computer and use it in GitHub Desktop.
Save mikelopez/3989173 to your computer and use it in GitHub Desktop.
Video player for samsung SDK
function SceneVideoPlayerFull(options){
this.options = options;
this.video_random_id = null;
// These item URL should be modified to contents URL to play.
this.playList = null;
}
SceneVideoPlayerFull.prototype.initialize = function(){
alert("SceneVideoPlayerFull.initialize()");
// this function will be called only once when the scene manager show this scene first time
// initialize the scene controls and styles, and initialize your variables here
// scene HTML and CSS will be loaded before this function is called
}
SceneVideoPlayerFull.prototype.setThePlaylistItems = function() {
// set the items array for the playlist contens that setItems() will use
alert('setThePlaylistItems() - set URL to /static/droid_tmp/pubvid/'+this.video_random_id);
this.playList = [{
url: 'http://204.13.2.45:8888/static/droid_tmp/pubvid/'+this.video_random_id+'.mp4',
title: 'Title1',
}];
}
SceneVideoPlayerFull.prototype.setItems = function() {
// set the video items that you want to use for the playlist
var items = [];
for(var i=0; i<this.playList.length; i++) {
items.push(this.playList[i].title);
}
$("#lstVideoPlayer").sfList({
data: items,
index: 0,
itemsPerPage: 8
}).sfList('blur');
return items;
}
SceneVideoPlayerFull.prototype.playTheVideo = function () {
var item = this.playList[$("#lstVideoPlayer").sfList('getIndex')];
item.fullScreen = true;
sf.service.VideoPlayer.setKeyHandler(sf.key.RETURN, function () {
sf.service.VideoPlayer.stop();
});
sf.service.VideoPlayer.play(item);
}
SceneVideoPlayerFull.prototype.handleShow = function(data){
alert("SceneVideoPlayerFull.handleShow()");
// set the random id and set the button callbacks
alert('VIDEO RANDOM ID = ' + data.video_random_id);
this.video_random_id = data.video_random_id;
this.setThePlaylistItems();
items = this.setItems();
var opt = {};
var _THIS_ = this;
opt.onerror = function(error, info){
var err = {};
err[sf.service.VideoPlayer.ERR_NOERROR] = 'NoError';
err[sf.service.VideoPlayer.ERR_NETWORK] = 'Network';
err[sf.service.VideoPlayer.ERR_NOT_SUPPORTED] = 'Not Supported';
_THIS_.printEvent('ERROR : ' + (err[error]||error) + (info ? ' (' + info + ')' : ''));
};
opt.onend = function(){
_THIS_.printEvent('END');
};
opt.onstatechange = function(state, info){
var stat = {};
stat[sf.service.VideoPlayer.STATE_PLAYING] = 'Playing';
stat[sf.service.VideoPlayer.STATE_STOPPED] = 'Stoped';
stat[sf.service.VideoPlayer.STATE_PAUSED] = 'Paused';
stat[sf.service.VideoPlayer.STATE_BUFFERING] = 'Buffering';
stat[sf.service.VideoPlayer.STATE_SCANNING] = 'Scanning';
_THIS_.printEvent('StateChange : ' + (stat[state]||state) + (info ? ' (' + info + ')' : ''));
};
sf.service.VideoPlayer.init(opt);
this.playTheVideo();
}
SceneVideoPlayerFull.prototype.handleHide = function(){
alert("SceneVideoPlayerFull.handleHide()");
// this function will be called when the scene manager hide this scene
}
SceneVideoPlayerFull.prototype.handleFocus = function(){
alert("SceneVideoPlayerFull.handleFocus()");
// this function will be called when the scene manager focus this scene
$("#Main_keyhelp").sfKeyHelp({
UPDOWN: 'Move Item',
ENTER: 'Play',
RETURN: 'Return'
});
$("#lstVideoPlayer").sfList('focus');
}
SceneVideoPlayerFull.prototype.handleBlur = function(){
alert("SceneVideoPlayerFull.handleBlur()");
// this function will be called when the scene manager move focus to another scene from this scene
$("#lstVideoPlayer").sfList('blur');
}
SceneVideoPlayerFull.prototype.handleKeyDown = function(keyCode){
alert("SceneVideoPlayerFull.handleKeyDown(" + keyCode + ")");
// TODO : write an key event handler when this scene get focued
switch (keyCode) {
case sf.key.UP:
$("#lstVideoPlayer").sfList('prev');
break;
case sf.key.DOWN:
$("#lstVideoPlayer").sfList('next');
break;
case sf.key.ENTER:
this.playTheVideo();
break;
case sf.key.LEFT:
case sf.key.RETURN:
sf.key.preventDefault();
sf.scene.hide('VideoPlayerFull');
Controller.showMain();
break;
}
}
SceneVideoPlayerFull.prototype.printEvent = function(msg){
alert("SceneVideoPlayerFull.prototype.printEvent("+msg+")");
var date = new Date();
var timestr = date.getHours() + ":" + date.getMinutes() + ":" + date.getSeconds();
document.getElementById("VideoPlayerFullEvent").innerHTML = timestr + '- ' + msg + '<br>' + document.getElementById("VideoPlayerFullEvent").innerHTML;
}
/* function SceneVideoPlayerFull(options){
this.options = options;
// These item URL should be modified to contents URL to play.
// THESE URLS GET REPLACED WITH CORRECT URL STREAM 100% SURE & DEBUGGED
this.playList = [{
url: 'http://myserver.com/1.mp4',
title: 'Title1',
},{
url: 'http://myserver.com/2.flv',
title: 'Title2'
}];
}
SceneVideoPlayerFull.prototype.initialize = function(){
alert("SceneVideoPlayerFull.initialize()");
// this function will be called only once when the scene manager show this scene first time
// initialize the scene controls and styles, and initialize your variables here
// scene HTML and CSS will be loaded before this function is called
var items = [];
for(var i=0; i<this.playList.length; i++) {
items.push(this.playList[i].title);
}
$("#lstVideoPlayer").sfList({
data: items,
index: 0,
itemsPerPage: 8
}).sfList('blur');
}
SceneVideoPlayerFull.prototype.handleShow = function(){
alert("SceneVideoPlayerFull.handleShow()");
var opt = {};
var _THIS_ = this;
opt.onerror = function(error, info){
var err = {};
err[sf.service.VideoPlayer.ERR_NOERROR] = 'NoError';
err[sf.service.VideoPlayer.ERR_NETWORK] = 'Network';
err[sf.service.VideoPlayer.ERR_NOT_SUPPORTED] = 'Not Supported';
_THIS_.printEvent('ERROR : ' + (err[error]||error) + (info ? ' (' + info + ')' : ''));
};
opt.onend = function(){
_THIS_.printEvent('END');
};
opt.onstatechange = function(state, info){
var stat = {};
stat[sf.service.VideoPlayer.STATE_PLAYING] = 'Playing';
stat[sf.service.VideoPlayer.STATE_STOPPED] = 'Stoped';
stat[sf.service.VideoPlayer.STATE_PAUSED] = 'Paused';
stat[sf.service.VideoPlayer.STATE_BUFFERING] = 'Buffering';
stat[sf.service.VideoPlayer.STATE_SCANNING] = 'Scanning';
_THIS_.printEvent('StateChange : ' + (stat[state]||state) + (info ? ' (' + info + ')' : ''));
};
sf.service.VideoPlayer.init(opt);
}
SceneVideoPlayerFull.prototype.handleHide = function(){
alert("SceneVideoPlayerFull.handleHide()");
// this function will be called when the scene manager hide this scene
}
SceneVideoPlayerFull.prototype.handleFocus = function(){
alert("SceneVideoPlayerFull.handleFocus()");
// this function will be called when the scene manager focus this scene
$("#Main_keyhelp").sfKeyHelp({
UPDOWN: 'Move Item',
ENTER: 'Play',
RETURN: 'Return'
});
$("#lstVideoPlayer").sfList('focus');
}
SceneVideoPlayerFull.prototype.handleBlur = function(){
alert("SceneVideoPlayerFull.handleBlur()");
// this function will be called when the scene manager move focus to another scene from this scene
$("#lstVideoPlayer").sfList('blur');
}
SceneVideoPlayerFull.prototype.handleKeyDown = function(keyCode){
alert("SceneVideoPlayerFull.handleKeyDown(" + keyCode + ")");
// TODO : write an key event handler when this scene get focued
switch (keyCode) {
case sf.key.UP:
$("#lstVideoPlayer").sfList('prev');
break;
case sf.key.DOWN:
$("#lstVideoPlayer").sfList('next');
break;
case sf.key.ENTER:
var item = this.playList[$("#lstVideoPlayer").sfList('getIndex')];
item.fullScreen = true;
sf.service.VideoPlayer.setKeyHandler(sf.key.RETURN, function () {
sf.service.VideoPlayer.stop();
});
sf.service.VideoPlayer.play(item);
break;
case sf.key.LEFT:
case sf.key.RETURN:
sf.key.preventDefault();
sf.scene.hide('VideoPlayerFull');
Controller.showMain();
break;
}
}
SceneVideoPlayerFull.prototype.printEvent = function(msg){
alert("SceneVideoPlayerFull.prototype.printEvent("+msg+")");
var date = new Date();
var timestr = date.getHours() + ":" + date.getMinutes() + ":" + date.getSeconds();
document.getElementById("VideoPlayerFullEvent").innerHTML = timestr + '- ' + msg + '<br>' + document.getElementById("VideoPlayerFullEvent").innerHTML;
}
*/
Copy link

ghost commented Mar 15, 2016

Hi, I see you have quite a good understanding of this stuff. I am using sf.service.VideoPlayer on Samsung TV and everything is good except when players starts playing it short displays its interface on top and then it hides it again. Do you have an idea how to avoid this?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment