Titanium Community Questions & Answer Archive

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

Full-screen video player in 1.4 / iOS4

I've been looking through a number of threads on the topic, and am still coming out confused.

I have a table view with a bunch of videos listed. When the user clicks a row, I want them to be taken to a full-screen video player in widescreen (landscape) orientation to see the video. When it's complete or they click Done, they're returned to the table view.

This used to be accomplished with something like this:

var activeMovie = Ti.Media.createVideoPlayer({...});
activeMovie.play();

In 1.4 the videoPlayer behaviour is much different. I was eventually able to cobble together something like the old behaviour (adding a new window, adding videoPlayer to it, setting videoPlayer to fullscreen, changing orientationModes, listening for leaving fullscreen so I can stop & release videoPlayer and close window…), but performance on the device was terrible - took a long time to get into and out of the player, and video wouldn't play smoothly.

If someone could provide a working example for emulating the old behaviour of videoPlayer, I would greatly appreciate it.

Thanks!

— asked August 10th 2010 by Nick Haffie-Emslie
  • 1.4
  • ios4
  • videoplayer
1 Comment
  • Found a bug report here - I'll keep an eye on it. In the meantime, please share any workarounds you're using!

    — commented August 11th 2010 by Nick Haffie-Emslie

4 Answers

  • OK I have something working similarly now. Not the most elegant because you still see the rotation, but it pretty much works:

    var win = Ti.UI.currentWindow;
    ...
    var activeMovie = Ti.Media.createVideoPlayer({
        url:videoURL,
        movieControlMode:Ti.Media.VIDEO_CONTROL_DEFAULT,
        scalingMode:Ti.Media.VIDEO_SCALING_ASPECT_FILL        // better than MODE_FILL, preserves aspect ratio
    });
    
    win.add(activeMovie);
    win.orientationModes = [Ti.UI.LANDSCAPE_RIGHT];
    activeMovie.fullscreen = true;
    activeMovie.play();
    
    activeMovie.addEventListener('fullscreen', function(e){   // when fullscreen status is changed
        if (!e.entering){                                     // user pressed "Done" or video finished
            win.remove(activeMovie);
            win.orientationModes = [Ti.UI.PORTRAIT];
        }
    });
    

    Not sure if this is the optimal approach, but it seems to be working. win.remove(activeMovie) is enough to release it from memory, correct?

    — answered August 12th 2010 by Nick Haffie-Emslie
    permalink
    2 Comments
    • I also ended up modifying this to check for OS3.2+ before doing

      win.add(activeMovie);
      win.orientationModes = [Ti.UI.LANDSCAPE_RIGHT];
      

      — commented August 13th 2010 by Nick Haffie-Emslie
    • Maybe something to do with my setup, but as soon as I call win.remove(activeMovie) my app bombs with an NSException. This is in iPhone running OS4 from Ti and SDK 4.0.2 installed. Driving me nuts this video player lark!

      — commented August 31st 2010 by Lee Sibbald
  • To be fair, I read Apple IOS 4 guideline, and that's how current SDk behave, not completely TI issue.

    However, there are many more problems you may encounter with this version of videoplayer.

    -On first video clip, a small spinner would stay there forever unless video is played back on fullscreen. The next movie will get rid of the problem though. So you must force video to load on fullscreen, otherwise, first clip will always has a spinner on top of the movie. I wish there's no default spinner, adding one myself then listening to loadstate would solve the issue.

    -Done button's not longer trigger anything, otherwise you could use that to close video. You still need a complete event handler for 3.2 and below devices.

    -Embeded movie (HTML 5) can't close on iPad (as universal app)

    — answered August 11th 2010 by Daniel Lim
    permalink
    1 Comment
    • Thanks for the insight Daniel. Do you know when this new treatment of videoPlayer was introduced? My app is pretty simple apart from the tableView that plays videos - maybe I can downgrade to a Titanium version with the old videoPlayer support, but that still supports export to iOS 4.0? Is there such a version?

      — commented August 11th 2010 by Nick Haffie-Emslie
  • 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
  • 25

    — answered June 19th 2012 by Bill Freedman
    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.