-1

I have mp3 and mp4 dat in url. I tried to play that in my ViewController so, i have created two players

audioPlayer = [[MPMoviePlayerController alloc]init];
videoPlayer  = [[MPMoviePlayerController alloc]init];

and assigned those links to the players -

Video

videoPlayer.contentURL = [NSURL URLWithString:video];
[videoPlayer prepareToPlay];

Audio

audioPlayer.contentURL = [NSURL URLWithString:audio];
[audioPlayer prepareToPlay];

Here i'm facing one issue that i can able to play one of them from above. It won't play either one is stopped after playing or initially its not allow to play both of them.

How do i fix this.

Praveenkumar
  • 24,084
  • 23
  • 95
  • 173
  • check out this link http://stackoverflow.com/questions/4368112/multiple-mpmovieplayercontroller-instances – Singh Apr 24 '13 at 07:37

1 Answers1

2

hi Praveen you have to use AVAudioPlayer for this type if task. please check bellow reference of :

http://developer.apple.com/library/ios/#DOCUMENTATION/AVFoundation/Reference/AVAudioPlayerClassReference/Reference/Reference.html

and you can play your mp3 file using bellow code and import AVFoundation.framework:-

    NSString *strURlString =@"yoururlwith.mp3"

    NSLog(@"%@",strURlString);

    strURlString =[strURlString stringByAddingPercentEscapesUsingEncoding:NSASCIIStringEncoding];

    NSLog(@"img url ==%@",strURlString);

    NSData *_objectData = [NSData dataWithContentsOfURL:[NSURL URLWithString:strURlString]];
    NSError *error;

    audioPlayer = [[AVAudioPlayer alloc] initWithData:_objectData error:&error];
    audioPlayer.numberOfLoops = 0;
    audioPlayer.volume = 1.0f;
    [audioPlayer prepareToPlay];

    if (audioPlayer == nil)
        NSLog(@"%@", [error description]);
    else
        [audioPlayer play];
Nitin Gohel
  • 49,482
  • 17
  • 105
  • 144