2011-06-27 36 views
1

在我的應用程序的音頻沒有被當我把我在後臺模式下的應用程序..我在這個網站看到過這樣的問題itself.it提到扮演的是播放音頻,而在後臺模式行不通

1)應用-的info.plist添加到背景模式在我添加了音頻會議

if([player isPlaying]) 
    { 
     [player stop]; 
    } 

     NSError *error=nil; 
     int trackid=arc4random()%10+1; 

     NSString *trackname=[NSString stringWithFormat:@"trk-%d",trackid]; 
    NSLog(@"%@",trackname); 
     NSString *newAudioFile = [[NSBundle mainBundle] pathForResource:trackname ofType:@"mp3"]; 
     player = [[AVAudioPlayer alloc] initWithContentsOfURL:[NSURL fileURLWithPath:newAudioFile] error:NULL]; 


     AVAudioSession *audioSession = [AVAudioSession sharedInstance]; 

     NSError *setCategoryError = nil; 
     [audioSession setCategory:AVAudioSessionCategoryPlayback error:&setCategoryError]; 
     if (setCategoryError) { /* handle the error condition */ } 

     NSError *activationError = nil; 
     [audioSession setActive:YES error:&activationError]; 
     if (activationError) { /* handle the error condition */ } 
     if(error) { 
      NSLog(@"%@",&error); 
     } 
     [player prepareToPlay]; 
     [player play]; 
     player.numberOfLoops=1; 

,但仍當我把應用研究背景mode.it恢復時,它是不工作的支持代碼「音頻」 2)我把應用程序放回去了。我錯過了什麼?

+0

當你把應用程序在其下研究背景模式存在,你必須加入「ADD播放音頻」項0。你有沒有添加這個? –

+0

亞,我已經提到(在應用程序info.plist禮儀??) – sujith1406

回答

1

使用該線路 - (無效)viewDidLoad中

[UIApplication sharedApplication].idleTimerDisabled = YES; 
+0

我試過這也同樣,音頻停止播放,而在後臺模式 – sujith1406

+0

不使用AVAudioSession - 使用AudioToolbox和 #import 看這裏 看看這篇文章http://oleb.net/blog/2009/07/the-music-player-framework-in-the-iphone-sdk/ – chewy