मैं आईओएस एप्लिकेशन में एक कस्टम वीडियो प्लेयर को लागू करने के लिए AVPlayer
का उपयोग कर रहा हूं।AVPlayer/AVPlayerItem मेरे एप्लिकेशन को पहुंचने योग्य नेटवर्क विफलता के बारे में कैसे सूचित करता है?
AVURLAsset *asset = [AVURLAsset URLAssetWithURL:self.URL
options:@{AVURLAssetPreferPreciseDurationAndTimingKey : @(YES)}];
लोड playable
कुंजी एसिंक्रोनस रूप:
NSArray *keys = @[@"playable"];
[asset loadValuesAsynchronouslyForKeys:keys completionHandler:^{
dispatch_async(dispatch_get_main_queue(), ^{
for (NSString *key in keys) {
NSError *error;
AVKeyValueStatus status = [asset statusOfValueForKey:key error:&error];
if (status == AVKeyValueStatusFailed) {
NSLog(@"Failed to load asset key %@ error %@", key, [error localizedDescription]);
[self fail];
return;
}
}
if (asset.isPlayable) {
[self.player replaceCurrentItemWithPlayerItem:self.playerItem];
}
else {
[self fail];
}
});
}];
समस्या है कि डिवाइस है जब
[[AVPlayer alloc] initWithURL:_URL];
एक परिसंपत्ति बनाएं: नेटवर्क से वीडियो चलाने के लिए मैं एक खिलाड़ी का आवंटन कोई इंटरनेट कनेक्शन या उच्च पैकेट नुकसान नहीं, completionHandler
कभी भी नहीं कहा जाता है (यहां तक कि मिनटों के इंतजार के बाद भी) और इसलिए मुझे नहीं पता कि लोड करने वाले उपयोगकर्ता को संदेश कब दिखाना है जी वीडियो असफल रहा।
मेरे प्रश्न हैं:
- Am मुझे याद आ रही कुछ/वहाँ एक बेहतर तरीका यह संभाल करने के लिए है?
- क्या मुझे अपना टाइमआउट तर्क रोल करना चाहिए या मुझे
loadValuesAsynchronouslyForKeys:
कभी नहीं करना चाहिए जबReachability
का मानना है कि नेटवर्क पहुंच योग्य नहीं है। AVPlayer
और नेटवर्क विफलताओं के बारे में सबसे अच्छा अभ्यास क्या हैं?