Skip to content

Instantly share code, notes, and snippets.

@iantearle
Created December 11, 2012 12:12
Show Gist options
  • Save iantearle/4258121 to your computer and use it in GitHub Desktop.
Save iantearle/4258121 to your computer and use it in GitHub Desktop.
movie player to play multiple videos. Needs ability to skip.
// Application Window Component Constructor
function Movie(_u, all) {
if(all) {
var mp4_array = ['12345.m4v', 'GrandOldDuke.m4v', 'TwinkleTwinkle.m4v', 'LittleBoPeep.m4v', 'LondonBridge.m4v', 'OldMotherHubbard.m4v', 'PataCake.m4v', 'PollyPutTheKettleOn.m4v', 'RockabyeBaby.m4v', 'TwinkleTwinkle.m4v'];
_u = mp4_array[0];
}
// Create our main window
var self = Titanium.Media.createVideoPlayer({
backgroundColor:'#111',
mediaControlStyle:Titanium.Media.VIDEO_CONTROL_FULLSCREEN,
allowsAirPlay:true,
contentURL: 'video/'+_u,
fullscreen:true
});
function playMovie(index){
self.contentURL = 'video/'+mp4_array[index];
self.play();
Ti.API.info('Videos, Play, ' + mp4_array[index]);
}
self.show();
var current_index = 0;
self.addEventListener('complete',function(e) {
if(all) {
current_index++;
console.log(current_index);
if(current_index < mp4_array.length) {
// play the next mp4 in the array
playMovie(current_index);
Ti.API.info('Videos, Next, ' + current_index);
} else {
Ti.API.info('all sounds complete!');
self.stop();
self.hide();
Ti.UI.iPhone.hideStatusBar();
sound.play();
}
} else {
if(e.reason == 0) {
self.stop();
self.hide();
Ti.UI.iPhone.hideStatusBar();
sound.play();
}
}
});
self.addEventListener('fullscreen', function(e){
if(e.entering == 0) {
self.hide();
Ti.UI.iPhone.hideStatusBar();
};
});
return self;
}
function PlayMovie() {
var self = this;
self.play();
return self;
}
//make constructor function the public component interface
Movie.prototype.play = PlayMovie
module.exports = Movie;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment