How do I play music using MPMusicPlayerController? - iphone

Can any one suggest me how to play the music using MPMusicPlayerController in my application.
Anyone's help will be very much appreciated.
Thank you,
Monish.

Create a MPMediaPickerController so you can choose some music from the iPod,
then in the mediaPicker:didPickMediaItems: call back you do this:
MPMusicPlayerController* playa;
playa = [MPMusicPlayerController applicationMusicPlayer];
[playa setQueueWithItemCollection:mediaItemCollection];
[playa play];

Related

Is it possible to interject your own audio once the ios media library has taken over?

I am wondering if it would be possible to insert your own audio once the ios media library has taken over in an app?
Example: Playing a piece of audio after every song that says the number of songs you've listened to that day.
I know that because its a framework there is only so many things they let you do.
This should be doable. To start, you can add your class as an observer of the MPMusicPlayerControllerNowPlayingItemDidChangeNotification to be informed when the song in the iPod library changes. From there, you can tell the iPod library to pause, play your track, and then resume music playback afterwards.
[[NSNotificationCenter defaultCenter] addObserver:self selector:#selector(someSel:) name:MPMusicPlayerControllerNowPlayingItemDidChangeNotification object:nil];
[[MPMusicPlayerController iPodMusicPlayer] pause];
// play your sound
[[MPMusicPlayerController iPodMusicPlayer] play];

Public API for iOS music player?

Is there any way I can access music playing in the native iOS music app? For example on button press in my app it pauses the built in Music app. I've tried MPMusicPlayerController but that doesn't seem to be what I want; or I'm not using it correctly.
This is what I've tried.
if ([musicPlayer playbackState] == MPMusicPlaybackStatePlaying) {
[musicPlayer pause];
} else {
[musicPlayer play];
}
Depends on how you instantiate your music player. To get access to the system global payer you should use:
MPMusicPlayerController *musicPlayer = [MPMusicPlayerController iPodMusicPlayer];
Be aware that if you're using applicationMusicPlayer it will only work for your application and pausing music will not affect the music playing in your Music.app.
See the MPMusicPlayerController documentation overview section for a more extensive description of the two.

AVAudioPlayer not smooth when play via bluetooth

I use AVAudioPlayer to play music file. It just works well when playing via headphone or speaker on iPhone body. But not smooth when playing via bluetooth. Why?
Here is my code:
AVAudioPlayer *newMusicPlayer = [[AVAudioPlayer alloc] initWithData:musicData error:&error];
if (!newMusicPlayer)
{
}
else
{
[newMusicPlayer play];
}
Special thx!
This is an apple's bug on 3GS running ios5.1.1, because "Music" is not smooth too.

MPMusicPlayerController not play on background

i am using MPMusicPlayerController in my app and when i enter to background it stop playing.
this is how i add it :
musicPlayer = [MPMusicPlayerController iPodMusicPlayer];
The iPodMusicPlayer is always enabled in the background. You shouldn't have to set anything. And [MPMusicPlayerController applicationMusicPlayer] won't play in the background ever. I'd say you're using the wrong MPMusicPlayerController somewhere.
You need to indicate in your app's plist file that you want to play audio in the background.
you create the applicationMusicPlayer it is not play in back ground.
you have to create ipodMusicPlayer to overcome this.
check this out for further refference.
http://developer.apple.com/library/ios/#documentation/MediaPlayer/Reference/MPMusicPlayerController_ClassReference/Reference/Reference.html#//apple_ref/doc/uid/TP40008221

iPhone MPMoviePlayer hide movie Control

hi i want hide movie control (Play - next - volume and ..)from MPMoviePlayer ...
what can i do ?
You can do this by this line of code
which hides the controls of the
player.
[player setMovieControlMode:MPMovieControlModeHidden];
Haven't tried it, but isn't there a setHidden:YES you can do?
iOS 3.2 and later use "setControlStyle" e.g.
[player setControlStyle:MPMovieControlStyleNone];
Check out the movieControlMode property of MPMoviePlayerController. You'll probably want MPMovieControlModeHidden.