Search code examples
iphonexcodeaudiompmovieplayercontrollermpmovieplayer

play mp3 file with MPMoviePlayer in background


I am using this MPMoviePlayerViewController to play .mp3 file from server but not working properly. Here is the code i am using.

NSString *path = @"http://myurl/music.mp3";
MPMoviePlayerViewController *mpviewController = [[MPMoviePlayerViewController alloc] initWithContentURL:[NSURL URLWithString:path]];
mpviewController.moviePlayer.movieSourceType = MPMovieSourceTypeStreaming;  
[self presentModalViewController:mpviewController animated:YES];
[[mpviewController moviePlayer] play];

Audio play for 3 or 5 seconds only then it stops automatically. Cant figure out whats the problem. Your suggestions would be great help.

Thank you.


Solution

  • Solved it by this code :) May it helps someone.

    NSString *path = @"http://myurl/mymusic.mp3";
    mv = [[MPMoviePlayerController alloc] initWithContentURL:[NSURL URLWithString:path]];
    mv.movieSourceType = MPMovieSourceTypeUnknown;
    [self.view addSubview:mv.view];
    [mv play];