Playing movies on iPhone (MPMoviePlayerController) blues..

Discussion in 'Game Development (Technical)' started by Jamie W, Sep 6, 2010.

  1. Jamie W

    Original Member Indie Author

    Joined:
    Apr 16, 2006
    Messages:
    1,211
    Likes Received:
    0
    Hope someone can help me with this, it's driving me nutty, and I'm about to stick pins in my eyes!..

    I'm trying to play-back a short (~30 seconds) movie clip, full-screen on iPhone.

    I've been looking at MPMoviePlayerController, but just can't seem to get it working.

    I'm now looking at this:

    http://developer.apple.com/iphone/l...ontroller.html#//apple_ref/doc/uid/TP40006953

    I have a sneaky feeling that I haven't set up the heirachy of views correctly...

    That needs doing right?

    My main view is an EAGLView : UIView (as I'm using OpenGL).
     
  2. chanon

    Indie Author

    Joined:
    Jul 28, 2004
    Messages:
    468
    Likes Received:
    0
    Not sure if you got it by now, but here's some code for you:

    Code:
        MPMoviePlayerController *moviePlayer = [[MPMoviePlayerController alloc] initWithContentURL:[NSURL fileURLWithPath:nstrMovieName]];
        moviePlayer.scalingMode = MPMovieScalingModeAspectFill;
        
        [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(myMovieFinishedCallback:) name:MPMoviePlayerPlaybackDidFinishNotification object:moviePlayer];
        
        float version = [[[UIDevice currentDevice] systemVersion] floatValue];
        if (version >= 3.2) {
            moviePlayer.controlStyle = MPMovieControlStyleNone;
    
            moviePlayer.view.transform = CGAffineTransformMakeRotation(M_PI/2.0);
            
            UIScreen *screen = [UIScreen mainScreen];
            CGRect newFrame = moviePlayer.view.frame;
            newFrame.size.width = screen.bounds.size.width;
            newFrame.size.height = screen.bounds.size.height;        
            
            moviePlayer.view.frame = newFrame;
            moviePlayer.useApplicationAudioSession = NO;
            
            [[UIApplication sharedApplication].keyWindow addSubview:moviePlayer.view];
            
            [moviePlayer play];
            
            MyOverlayView *oview = [[MyOverlayView alloc] initWithFrame:CGRectZero];
            oview.transform = CGAffineTransformMakeRotation(M_PI/2.0);
            [oview initMe];
            oview->moviePlayer = self;
            [moviePlayer.view addSubview:oview];
            overlay = oview;        
        }
        else {
            [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(handleKeyWindowChanged:)
                                                         name:UIWindowDidBecomeKeyNotification
                                                       object:nil];
            
            moviePlayer.movieControlMode = MPMovieControlModeHidden;
            [moviePlayer play];
        }
        
        m_moviePlayer = moviePlayer; 
    
    Taken out of our movie player code .. which looking at the whole thing again it seems pretty messy.

    The overlay view is added to detect touches to skip the movie. For older OSes the MPMoviePlayer thingy doesn't support getting the view property so to add the overlay view you have to listen to the key window changed event.

    But if you want to just play it then this should be enough.

    I'm no expert, just was able to hack it until it worked.
     
  3. Jamie W

    Original Member Indie Author

    Joined:
    Apr 16, 2006
    Messages:
    1,211
    Likes Received:
    0
    Thanks chanon! :)

    I've managed to get a movie playing, in a stand-alone app that's not using openGL (eaglView etc), but getting it to play nicely with openGL is another matter! So, I think the issue I'm having, is more one of conceptually understanting how the iPhone OS manages windows and views, and it's something I've not really had to understand until now (just been setting up openGL, then off I go, kinda thing).

    I found a couple of other good related resources and sample code, I'll share here incase anyone else finds them useful:

    http://www.drobnik.com/touch/2010/07/the-3-2-hurdle-of-mpmovieplayercontroller/

    http://iphonedevelopertips.com/vide...-ipad-and-earlier-versions-of-iphone-sdk.html

    Also, I'm finding this helpful:

    http://www.switchonthecode.com/tutorials/getting-started-with-opengl-es-for-the-iphone

    Just to get rid of the .nib file altogether, so it doesn't automatically setup the windows and openGL view etc. I want to play the movie first, before the openGL stuff gets setup.

    Thanks again,
    Jamie.
     
  4. FlagellumDei

    FlagellumDei New Member

    Joined:
    May 28, 2009
    Messages:
    68
    Likes Received:
    0
    Jamie W:

    I have the same problem. I cannot play movie in an app which is using OpenGL. I can hear the sound, but there's nothing displayed. Have you found a solution?
     
  5. Jamie W

    Original Member Indie Author

    Joined:
    Apr 16, 2006
    Messages:
    1,211
    Likes Received:
    0
    Yes, after a bit of research. In short, here's what I did.


    1. Delete the .nib file from the project.
    2. Edit main.m, to something like:
    int retVal = UIApplicationMain(argc, argv, nil, @"yourAppDelegate");
    3. Change eaglView, initWithCoder to initWithFrame

    More info on these 3 steps here:
    http://www.switchonthecode.com/tutorials/getting-started-with-opengl-es-for-the-iphone

    In you AppDelegate, you need to do stuff in following order..

    4. Create the window (you only have one of these).
    5. Create the eaglView object.
    6. Create the custom movie view controller object.
    (both 5 and 6, are member objects in the AppDelegate class).
    7. I then send a pointer to the custom movie view controller object, to my eaglView object.
    8. First attach the eaglView to your window.
    9. Then attach the custom movie player object view to your window.
    10. Make the window visible.
    11. Play the movie.
    12. Start the eaglView animating.
    13. Exit didFinishLaunchingWithOptions.


    In the eaglView function you've setup to be called 60fps, you need to know if the movie is playing .. i.e. a function in the custom movie view controller, isPlaying().

    If movie is playing, don't do anything with the eaglView (no updating game, no rendering).

    When the movie stops, you need to release the custom movie view controller, and have something in it's dealloc, that will remove it's view from super view (e.g. [self.view removeFromSuperview]).

    So basically, you have one window, and can attach multlipe views to it, in a heirachy fashion. If you have 2 views at the same level (as is the case here), it's the last view you added that gets displayed; remove that view, and the other view, at that level, gets rendered instead.

    Hope that helps, and good luck!

    EDIT: Also, some of the apple developer docs were pretty useful. iOS Application Programming Guide page 39 touches on Windows and Views (briefly), and that's what you need to understand for this, how the window and views stuff work in iOS.
     
  6. Four

    Four New Member

    Joined:
    Aug 30, 2008
    Messages:
    30
    Likes Received:
    0
    I had a similar problem (Sound but no video) and it turns out 3.2 and after requires you to specifically add the view of the movie controller somewhere in your view hierarchy. Like maybe the top level window.

    And before 3.2 it adds it automatically,
     
  7. FlagellumDei

    FlagellumDei New Member

    Joined:
    May 28, 2009
    Messages:
    68
    Likes Received:
    0
    Jamie W:

    After I delete the .nib and change the initWithCoder to initWithFrame like in that tutorial, I get messages like this in the console when running in the Simulator:

    Detected an attempt to call a symbol in system libraries that is not present on the iPhone:
    open$UNIX2003 called from function _ZN4llvm12MemoryBuffer7getFileEPKcPSsx in image libLLVMContainer.dylib.


    The game runs fine. On running on the device there are no such messages. I get the same messages when running the sample app from that tutorial. Are you also getting these messages?
     
  8. Jamie W

    Original Member Indie Author

    Joined:
    Apr 16, 2006
    Messages:
    1,211
    Likes Received:
    0
    Nope, sorry, didn't get anything like that, or any other error messages.

    Did you try creating a new EAGLView project, just to check out the process of moving from .nib file / initWithCoder to no .nib file /initWithFrame?
     
  9. MelvinThomas

    MelvinThomas New Member

    Joined:
    Nov 21, 2020
    Messages:
    1
    Likes Received:
    0
    You can watch movies in high quality when installing mx player pro at techbigs. This is an application that allows you to play your favorite videos and movies for free with the best quality.
     
    #9 MelvinThomas, Nov 21, 2020
    Last edited: Nov 25, 2020 at 3:48 AM

Share This Page

  • About Indie Gamer

    When the original Dexterity Forums closed in 2004, Indie Gamer was born and a diverse community has grown out of a passion for creating great games. Here you will find over 10 years of in-depth discussion on game design, the business of game development, and marketing/sales. Indie Gamer also provides a friendly place to meet up with other Developers, Artists, Composers and Writers.
  • Buy us a beer!

    Indie Gamer is delicately held together by a single poor bastard who thankfully gets help from various community volunteers. If you frequent this site or have found value in something you've learned here, help keep the site running by donating a few dollars (for beer of course)!

    Sure, I'll Buy You a Beer