【发布时间】:2015-09-16 23:25:51
【问题描述】:
我正在使用 AVPlayer 播放来自 url 的音频,但是当 iPhone 连接到蓝牙设备时,它没有通过蓝牙播放,如果连接了如何通过蓝牙播放,我在 SO 中看到了一些帖子,但没有其中有明确的解释。下面是我的代码。
-(void)playselectedsong{
AVPlayer *player = [[AVPlayer alloc]initWithURL:[NSURL URLWithString:urlString]];
self.songPlayer = player;
[[NSNotificationCenter defaultCenter] addObserver:self
selector:@selector(playerItemDidReachEnd:)
name:AVPlayerItemDidPlayToEndTimeNotification
object:[songPlayer currentItem]];
[self.songPlayer addObserver:self forKeyPath:@"status" options:0 context:nil];
[NSTimer scheduledTimerWithTimeInterval:0.1 target:self selector:@selector(updateProgress:) userInfo:nil repeats:YES];
[self.songPlayer play];
}
- (void)observeValueForKeyPath:(NSString *)keyPath ofObject:(id)object change:(NSDictionary *)change context:(void *)context {
if (object == songPlayer && [keyPath isEqualToString:@"status"]) {
if (songPlayer.status == AVPlayerStatusFailed) {
NSLog(@"AVPlayer Failed");
} else if (songPlayer.status == AVPlayerStatusReadyToPlay) {
NSLog(@"AVPlayerStatusReadyToPlay");
} else if (songPlayer.status == AVPlayerItemStatusUnknown) {
NSLog(@"AVPlayer Unknown");
}
}
}
- (void)playerItemDidReachEnd:(NSNotification *)notification {
// code here to play next sound file
}
【问题讨论】:
-
您的意思是根本不通过蓝牙播放,还是在播放歌曲时从扬声器切换到蓝牙时不通过蓝牙播放?
-
@MDB983:它根本不是通过蓝牙播放的。
-
@MDB983:关于这个问题的任何想法,请帮助我。
-
我找到了这篇文章。它可能对你有帮助。 stackoverflow.com/questions/17482608/…
标签: ios iphone bluetooth avaudioplayer avplayer