Titanium Community Questions & Answer Archive

We felt that 6+ years of knowledge should not die so this is the Titanium Community Questions & Answer Archive

'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?

— asked October 21st 2010 by Ronnie Swietek
  • complete
  • event
  • video_finish_reason_user_exited
0 Comments

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

    — answered October 25th 2010 by John McKnight
    permalink
    2 Comments
    • Worked for me! Thank's @JohnMacKnight

      — commented July 20th 2011 by Emmanuel Balpe
    • Worked for me too, but with a minor change to the code - calling movie.stop() triggers the 'complete' event, answering the OP's question.

              activeMovie.addEventListener('fullscreen',function(e)
              {
                if (e.entering === false) {
                  // left fullscreen AKA done may have been pressed.  
                  activeMovie.stop();
                }
              });
      

      — commented October 19th 2011 by Jeff Antram
  • 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.

    — answered December 24th 2010 by Alan Lougher
    permalink
    0 Comments
  • This should help, just posted it.
    http://developer.appcelerator.com/question/135367/fullscreen-video-player-example-works

    — answered April 13th 2012 by Casey McLaughlin
    permalink
    0 Comments
  • 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 :(

    — answered October 22nd 2010 by Ronnie Swietek
    permalink
    0 Comments
  • I am still having this problem. Any clue as to why this event isn't firing?

    — answered October 25th 2010 by Ronnie Swietek
    permalink
    0 Comments
The ownership of individual contributions to this community generated content is retained by the authors of their contributions.
All trademarks remain the property of the respective owner.