'complete' event not firing when hitting 'done'
I have a video and when I hit the done button, the complete event isnt firing:
var win = Titanium.UI.currentWindow;
var video = win.video;
var activeMovie = Titanium.Media.createVideoPlayer({
contentURL: video,
backgroundColor:'#111',
fullscreen:true,
movieControlMode:Titanium.Media.VIDEO_CONTROL_EMBEDED,
scalingMode:Titanium.Media.VIDEO_SCALING_MODE_FILL
});
activeMovie.addEventListener('complete',function(e)
{
// Only fires when video ends
Ti.API.info(e);
});
win.add(activeMovie);
win.orientationModes = [
Titanium.UI.LANDSCAPE_LEFT,
Titanium.UI.LANDSCAPE_RIGHT
];
activeMovie.play();
According to the API, this event should fire when hitting the done button:
VIDEO_FINISH_REASON_USER_EXITED - the video playback ended by user action (such as clicking the Done button)
And according to the API docs for VideoPlayer:
complete
fired when movie playback ends or a user exits playback
Event properties
reason
the completion reason. One of Titanium.Media.VIDEO_FINISH_REASON_PLAYBACK_ENDED,
Titanium.Media.VIDEO_FINISH_REASON_PLAYBACK_ERROR or
Titanium.Media.VIDEO_FINISH_REASON_USER_EXITED.
source the source object that fired the event
type the name of the event fired
Any ideas?
6 Answers
-
According to Apple…
MPMoviePlayerPlaybackDidFinishNotification
Notifies observers that the movie finished playing. The affected movie player is stored in the object parameter of the notification. The userInfo dictionary of this notification contains the MPMoviePlayerPlaybackDidFinishReasonUserInfoKey key, which indicates the reason that playback finished. This notification is also sent when playback fails because of an error.
This notification is not sent in cases where the movie player is displaying in fullscreen mode and the user taps the Done button. In that instance, the Done button causes movie playback to pause while the player transitions out of fullscreen mode. If you want to detect this scenario in your code, you should monitor other notifications such as MPMoviePlayerDidExitFullscreenNotification.
Given this info, the way to detect done would be this:
activeMovie.addEventListener('fullscreen',function(e) { if (e.entering == 0) { // left fullscreen AKA done may have been pressed. } else if (e.entering == 1) { // entered fullscreen, the video probably started playing. } });
Yes, it does fire and this is what I saw when I clicked done.
[INFO] { duration = 0.4; entering = 0; source = [object TiMediaVideoPlayer]; type = fullscreen; }
ADDENDUM: Yes, the documentation is wrong when it comes to iOS behavior.
If you liked my answer, vote me up and close the ticket. Thanks
-
Has this been fixed yet? I've tried the solution posted by John above which works fine, except if the user switches from fullscreen to normal the video will stop and close. So while the solution works for the Done button it also closes if the video is resized using the <> button.
-
i have the same problem (i work on ios 5 with ti. 1.8.1)
please check my post.
inline http://developer.appcelerator.com/question/132710/video-fullscreen-with-done-button
thanks!
-
This should help, just posted it.
http://developer.appcelerator.com/question/135367/fullscreen-video-player-example-works -
I tried doing an event listener for playbackState and hitting pause and the done button produce the same int which is 2. 2 must be paused. Anyone have any suggestions? I cant continue :(
-
I am still having this problem. Any clue as to why this event isn't firing?