MPMoviePlayer rotates to landscape

Discussion in 'iPhone/iPad Programming' started by Danneman101, Mar 5, 2009.

  1. macrumors 6502

    Joined:
    Aug 14, 2008
    #1
    Ive tried implementing a MPMoviePlayerController to play mp3's. Problem is my app is entirely in portrait-mode, whereas when the MPMoviePlayer loads it rotates the screen to landscape-mode.

    Im guessing there is a property that should adress this, but after messing around with both movieControlMode and scalingMode it persists on appearing in landscape.

    Code:
    	// Init:		MPPlayer
    	mpPlayer = [[MPMoviePlayerController alloc] initWithContentURL:[NSURL fileURLWithPath:soundPath]];
    		
    	// Ive tried all these: MPMovieControlModeDefault, MPMovieControlModeVolumeOnly, MPMovieControlModeHidden.
    	mpPlayer.movieControlMode = MPMovieControlModeDefault;
    						 
    	// Ive tried all these MPMovieScalingModeNone, MPMovieScalingModeAspectFit, MPMovieScalingModeAspectFill, MPMovieScalingModeFill.
    	mpPlayer.scalingMode = MPMovieScalingModeAspectFill;
    		
    	// Release:		Release object after play
    	[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(MPMovieFinished:) name:MPMoviePlayerPlaybackDidFinishNotification object:nil];
    
    	// Play:		Sound
    	[mpPlayer play];
    
    Any ideas how I can make it stick to portrait-mode?
     
  2. Moderator

    dejo

    Staff Member

    Joined:
    Sep 2, 2004
    Location:
    The Centennial State
    #2
    Why are you using the movie player to play MP3s? Shouldn't you just use an audio player, like Audio Toolbox or Audio Queue or ...?
     
  3. thread starter macrumors 6502

    Joined:
    Aug 14, 2008
    #3
    I guess I got scared when I tried reading up on them :p I got the impression that to play a single mp3-file I had to write an inmense amount of code, and even include some code in c. Perhaps Im wrong?

    I can use:
    Code:
    [[UIApplication sharedApplication] setStatusBarOrientation:UIInterfaceOrientationPortrait animated:YES];
    
    But that makes the view rotate and then rotate back, causing flicker.
     
  4. Moderator

    dejo

    Staff Member

    Joined:
    Sep 2, 2004
    Location:
    The Centennial State
    #4
    animated:NO perhaps?
     
  5. thread starter macrumors 6502

    Joined:
    Aug 14, 2008
    #5
    It did diminish the flickering somewhat, so half way there :)

    Im not entirely sure that the flickering will persist when running on a real device though. The screen does not seem to rotate at all, but rather its the iphone simulator that rotates - probably standard behaviour when loading a MPMediaPlayerController...? So maby this isnt even an issue, and the app will work without rotating when on a real device :)

    Problem is I cant try it out since Im having awful problems with signing my app to my iPhone...which seems to be very common *cant imagine why they made it so complicated*
     
  6. Moderator

    dejo

    Staff Member

    Joined:
    Sep 2, 2004
    Location:
    The Centennial State
    #6
    I can. To keep the script-kiddies out. ;)
     
  7. macrumors regular

    Joined:
    Jun 18, 2008
    #7
    The MPMoviePlayer does that. Always. There's nothing you can do about it.

    You should use the new AVAudioPlayer instead. Much simpler than Audio Queue or Core Audio.
     
  8. thread starter macrumors 6502

    Joined:
    Aug 14, 2008
    #8
    I resent that ;) hehe


    ghayenga: I havent heard about that one, but if it's simpler then Im game :)
    However, I would like to be able to see my other view with its text when playing the sound. Is that possible, or does the AVAudioPlayer switch to another player-gui?
    And is it only supported in 2.2?
     
  9. Moderator

    dejo

    Staff Member

    Joined:
    Sep 2, 2004
    Location:
    The Centennial State
    #9
    Oops, you're not a dastardly script-kiddie, are you? :eek:
     
  10. thread starter macrumors 6502

    Joined:
    Aug 14, 2008
    #10
    I dont know if my skills are even up to par with a script-kiddie when it comes to iPhone-development :eek: :p

    Anyway, Im trying my best, and this forum is invaluable, so thank you for all the help Ive been getting :)
     
  11. macrumors regular

    Joined:
    Jun 18, 2008
    #11
    No it has no interface of it's own. So no problem for you there. It was introduced in 2.2, so yes 2.2 and up only.
     
  12. thread starter macrumors 6502

    Joined:
    Aug 14, 2008
    #12
    Ok, thanks a lot :) I think Ill keep it simple without a stop-button or any other gui, though, since the sound-files are all shorter than 5 seconds.
     

Share This Page