मेरे पास एक ऑडियो प्लेयर है जिसे मैं एवीप्लेयर का उपयोग कर बना रहा हूं।AVPlayer replaceCurrentItemWithPlayerItem आईओएस पर काम नहीं कर रहा है 4.3.3+
वर्तमान में, मैं चारों ओर player
उदाहरण रखने के लिए और मैं एक नया AVPlayerItem
बनाने जब मैं पटरियों स्वैप करने के लिए (या तो एक मैनुअल चयन से या ट्रैक अंत तक पहुँच गया है) की जरूरत है और मैं नए आइटम के साथ replaceCurrentItemWithPlayerItem
कहते हैं।
दस्तावेज़ों के मुताबिक, replaceCurrentItemWithPlayerItem
एक असीमित ऑपरेशन है, इसलिए मैं वर्तमान इटैम प्लेयर का मुख्य पथ भी देखता हूं। जब इसे बुलाया जाता है, तो मैं अपने खिलाड़ी को खेलने के लिए कहता हूं। यहाँ
AVPlayerItem *playerItem = [AVPlayerItem playerItemWithAsset:asset];
[playerItem addObserver:self forKeyPath:@"status" options:NSKeyValueObservingOptionNew context:CHStreamingAudioPlayer_PlayerItemStatusChangedContext];
if (!_player) {
_player = [[AVPlayer alloc] initWithPlayerItem:playerItem];
[_player addObserver:self forKeyPath:@"status" options:NSKeyValueObservingOptionNew context:CHStreamingAudioPlayer_PlayerStatusChangedContext];
[_player addObserver:self forKeyPath:@"currentItem" options:NSKeyValueObservingOptionNew context:CHStreamingAudioPlayer_PlayerCurrentItemChangedContext];
} else {
[_player replaceCurrentItemWithPlayerItem:playerItem];
}
और कुंजी मान अवलोकन कॉलबैक है:
यहाँ प्रासंगिक कोड है
- (void)observeValueForKeyPath:(NSString *)keyPath ofObject:(id)object change:(NSDictionary *)change context:(void *)context {
if (context == CHStreamingAudioPlayer_PlayerCurrentItemChangedContext) {
NSLog(@"Player's current item changed! Change dictionary: %@", change);
if (_player.currentItem) {
[self play]; //<---- doesn't get called
}
} else {
[super observeValueForKeyPath:keyPath ofObject:object change:change context:context];
}
}
आईओएस 4.3.3 (और iOS 5) पर मेरी कुंजी अवलोकन विधि कहा जाता है लेकिन _player.currentItem
हमेशा nil
है। 4.2.1 और 4.3.2 पर इस संपत्ति में वास्तविक मूल्य है। इस विधि को फिर कभी नहीं बुलाया जाता है। तो संक्षेप में, प्रतिस्थापन हमेशा असफल लगता है।
यह एक बग की तरह लगता है, लेकिन शायद मैं कुछ गलत कर रहा हूं।
Dunja से नीचे इस सवाल का जवाब आपकी समस्या का समाधान हुआ? –