AVQueuePlayer - Получить длительность всех элементов (AVPlayerItem) в AVQueuePlayer до запуска аудио - PullRequest
0 голосов
/ 24 сентября 2019

У меня есть список AVPLayerItems с URL'ами в AVQueuePlayer.Мне нужно узнать длительность всех предметов, прежде чем игрок начнет играть.Приведенное ниже решение отлично работает в iOS 10.

Я играю аудио, в котором есть несколько дорожек.Необходимо извлечь длительность всех треков, а затем запустить плеер.Пробовал с item.assest.duration, item.duration, loadValuesAsynchronouslyForKeys с продолжительностью ключа.Все они дают Nan или 0 или AVKeyValueStatusFailed

NSRUR *URL1 = @"https://example.com/Audio_1.mp3";
NSRUR *URL2 = @"https://example.com/Audio_2.mp3";
NSRUR *URL3 = @"https://example.com/Audio_3.mp3";
NSRUR *URL4 = @"https://example.com/Audio_4.mp3";
NSArray* urlArr = [NSArray arrayWithObjects: URL1,URL2,URL3,URL4,nil];                         
NSMutableArray *items = [NSMutableArray new];
for (URL in urlArr){
AVURLAsset *asset = [[AVURLAsset alloc] initWithURL:URL options:nil];
AVPlayerItem *item = [AVPlayerItem playerItemWithAsset:asset];
[items addObject:item];
}
AVQueuePlayer *player = [[AVQueuePlayer alloc] initWithItems:items]; 
[player play];                                                     


// For updating progress bar 
for (NSInteger i = 0; i < items.count; i++)
{
AVPlayerItem *item = self.playerItems[i];
duration += CMTimeGetSeconds(item.assest.duration);
}
//I only get the duration for the first item
//tried both item.duration and item.asset.duration
Добро пожаловать на сайт PullRequest, где вы можете задавать вопросы и получать ответы от других членов сообщества.
...