var VideoPlayer = function (elem) {
var player = null, playSpeed = 0, elemParent, updateInfoCallback, dataItems;
/*
Initialize the canvas elements and data source.
*/
this.Init = function (_elemParent, _playSpeed, _updateInfoCallback) {
playSpeed = _playSpeed;
elemParent = _elemParent;
updateInfoCallback = _updateInfoCallback;
resetPlayer();
};
/*
Start to play.
*/
this.Play = function (_dataItems) {
dataItems = _dataItems;
player.Play(_dataItems);
};
/*
Stop to play the images.
*/
this.Stop = function () {
player.Stop();
};
/*
Reset playing context.
*/
this.Reset = function () {
player.Reset();
}
/*
Request full screen
*/
this.FullScreen = function () {
player.FullScreen();
return true;
}
this.Seek = function (pos) {
player.Seek(pos);
return true;
}
/*
Exit full screen.
*/
this.ExitFullScreen = function () {
player.ExitFullScreen();
return true;
}
/*
Get video real dimension.
*/
this.Getdimension = function () {
return player.Getdimension();
}
function resetPlayer() {
var isHTML5Video = true;
var supportedArray = new Array(".mp4", ".mkv", ".avi", ".flv", ".h264", ".asf");
var supported = false;
fileExt = fileExt.toLowerCase();
for (var i = 0; i < supportedArray.length; i++)
{
if (fileExt == supportedArray[i])
{
supported = true;
break;
}
}
if (!supported)
{
player = new videoUnsupported();
player.Init(elemParent, playSpeed, updateInfoCallback);
return;
}
var needReinit = true;
if (playSpeed != 1000) {
if (!isHTML5Video) {
if (player == null || !(player instanceof (videoPluginPlayer))) {
player = new videoPluginPlayer();
player.PlayDelay = playSpeed;
} else {
needReinit = false;
try {
player.SetFramerate(playSpeed);
} catch (e) { }
}
} else {
if (player == null || !(player instanceof (videoNormalPlayer))) {
player = new videoNormalPlayer();
player.PlayDelay = playSpeed;
} else {
player.SetFramerate(playSpeed);
needReinit = false;
}
}
} else {
player = new videoFastPlayer();
}
if (needReinit) {
player.Init(elemParent, playSpeed, updateInfoCallback);
}
}
this.ChangeSpeed = function (_playSpeed) {
if (player != null) {
var playingVideo = player.GetPlayingVideo();
if (playingVideo == null ||
playingVideo == undefined) {
return false;
}
player.Stop();
//player.Reset();
if (dataItems != null && dataItems.length == 0)
dataItems.push(playingVideo); //to prevent the datasource is empty!
}
playSpeed = _playSpeed;
resetPlayer();
player.Play(dataItems);
return true;
}
this.Mute = function () {
if (player != null)
player.Mute();
};
return this;
}