PDA

View Full Version : MPMoviePlayer rotates to landscape




Danneman101
Mar 5, 2009, 01:58 PM
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.


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



dejo
Mar 5, 2009, 02:27 PM
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 ...?

Danneman101
Mar 5, 2009, 03:02 PM
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:

[[UIApplication sharedApplication] setStatusBarOrientation:UIInterfaceOrientationPortrait animated:YES];


But that makes the view rotate and then rotate back, causing flicker.

dejo
Mar 5, 2009, 03:36 PM
But that makes the view rotate and then rotate back, causing flicker.
animated:NO perhaps?

Danneman101
Mar 5, 2009, 03:51 PM
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*

dejo
Mar 5, 2009, 04:34 PM
*cant imagine why they made it so complicated*
I can. To keep the script-kiddies out. ;)

ghayenga
Mar 5, 2009, 05:32 PM
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:

[[UIApplication sharedApplication] setStatusBarOrientation:UIInterfaceOrientationPortrait animated:YES];


But that makes the view rotate and then rotate back, causing flicker.

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.

Danneman101
Mar 5, 2009, 06:52 PM
I can. To keep the script-kiddies out. ;)

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?

dejo
Mar 5, 2009, 06:53 PM
I resent that ;) hehe
Oops, you're not a dastardly script-kiddie, are you? :o

Danneman101
Mar 5, 2009, 07:09 PM
Oops, you're not a dastardly script-kiddie, are you? :o

I dont know if my skills are even up to par with a script-kiddie when it comes to iPhone-development :o :p

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

ghayenga
Mar 6, 2009, 11:21 AM
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?

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.

Danneman101
Mar 10, 2009, 12:30 PM
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.

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.