2013-04-24 152 views
0

我在網址中有mp3mp4 dat。我試着玩,在我ViewController所以,我已經創建了兩個球員使用MPMoviePlayerController播放mp3和mp4文件

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

和分配這些鏈接的球員 -

視頻

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

音頻

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

在這裏,我正面臨一個問題,我可以從上面玩他們其中的一個。它不會播放任何一個播放後停止或最初不允許播放它們。

我該如何解決這個問題。

+0

退房此鏈接http://stackoverflow.com/questions/ 4368112/multiple-mpmovieplayercontroller-instances – Singh 2013-04-24 07:37:12

回答

2

嗨Praveen你必須使用AVAudioPlayer這種類型,如果任務。請檢查波紋管參考:

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

,您可以使用波紋管代碼播放MP3文件,並導入AVFoundation.framework: -

NSString *strURlString [email protected]"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]; 
+0

工作正常!謝謝! – Praveenkumar 2013-04-24 13:21:36