2014-11-03 34 views
0

我已经为此工作了3个小时,并且找不到解决方案。 我正在使用第三方库,为我播放声音,我猜他们正在使用AVAudioPlayer playSound,并且我想知道,如果有方法可以知道我的应用程序是否在播放声音。检查应用程序中是否播放了音频

我无权访问第三方库,并且播放该声音的媒体资源是私有的。 我一直在尝试AVAudioSession,但只有两种不同的方法来检查是否有声音播放,不幸的是它只能检查来自应用程序外部的声音。

感谢

+0

你有没有发现这方面的任何解决方案? – 2015-07-01 10:58:41

回答

-1
//Register self for remote notifications of play/pause toggle  
//(i.e. when user backgrounds app, double-taps home, 
    //then swipes right to reveal multimedia control buttons). 
    //See MyWindow.h for more info.  

Add this Notification Center where to detect playback 

[[NSNotificationCenter defaultCenter] addObserver:self            selector:@selector(toggling_Playback)             name:@"TogglePlayPause" object:nil]; 

- (void)toggling_Playback {  
    (self.player.isPlaying ? [self.player pause] : [self.player play]); 
} 


AVAudioPlayerDelegate protocol methods: 

- (void)audioPlayerDidFinishPlaying:(AVAudioPlayer *)p successfully:(BOOL)flag { 
    [self.player stop];   
    [self ffButtonWasPressed]; 
    } 

- (void)audioPlayerBeginInterruption:(AVAudioPlayer *)player {  
//In real app, may persist this to NSUserDefaults to act on after interruption ends 
    //or app resumes.  
NSLog(@"Interruption began"); 

} 

//Note: this form is only for iOS >= 4.0. See docs for pre-4.0. 

- (void)audioPlayerEndInterruption:(AVAudioPlayer *)player withFlags:(NSUInteger)flags { 
    NSLog(@"Interruption ended"); 
    //restart playback if flag indicates we should resume 
    if (flags & AVAudioSessionInterruptionFlags_ShouldResume)  {  
    [self toggling_Playback];  
} 
} 

如果您还有任何的疑问:仔细查阅此链接 http://www.allappsdevelopers.com/TopicDetail.aspx?TopicID=99cb8bf0-91ac-4c41-a903-2dc744444b7a

相关问题