Playing multiple videos in succession in a Ti.Media.VideoPlayer in Android
I am using Titanium Mobile Framework 1.6.2, Building against Android 2.2.
I have successfully written code to play a "playlist" of videos in a video player in succession in iPhone. All attempts to get similar functionality working in Android has failed.
For the code that follows assume that this 'videoPlayer' object is being rendered on a View called 'videoView'.
var cindex = 0;
var fpaths = [{"url":"../movie.mp4"},
{"url":"../movie3.mp4"}];
var videoPlayer = Titanium.Media.createVideoPlayer({
width: 315,
height: 100,
left: 0,
autoPlay: false,
top: -111,
backgroundColor: '#FFF',
mediaControlStyle: Ti.Media.VIDEO_CONTROL_DEFAULT,
movieControlMode: Ti.Media.VIDEO_CONTROL_DEFAULT,
sourceType: Titanium.Media.VIDEO_SOURCE_TYPE_FILE,
scalingMode:Titanium.Media.VIDEO_SCALING_ASPECT_FIT,
contentURL: fpaths[cindex].url,
fullscreen:false
});
var onComplete = function() {
Ti.API.info('video complete, play next');
if (fpaths.length > 1 && (cindex < fpaths.length - 1))
{
Ti.API.info("incrementing cindex");
cindex++;
Ti.API.info("new URL: " + fpaths[cindex].url);
videoPlayer.contentURL = fpaths[cindex].url
Ti.API.info("vp.contentURL: " + videoPlayer.contentURL);
videoPlayer.play();
}
};
videoPlayer.addEventListener('complete', onComplete);
videoPlayer.play();
The first video plays without issue, but once it completes it gets as far as updating the contentURL and then the first video plays again.
I have attempted to set the 'url' parameter as well as use the 'setUrl' method as well, with no luck.
I have tried releasing the player and creating a new one and binding it to the view, with no luck.
I have attempted all manner of hiding and showing the view, with no luck.
I have attempted to load multiple instances of this view with updated 'cindex' values to sit on top of each other (a hack to see if we could get multiple videos), with no luck.
1 Answer
-
>…assume that this 'videoPlayer' object is being rendered on a View called 'videoView'.
In Android, the video player must not be added to another view.