ユーザーがローカルビデオファイルから選択できるアプリケーションがあります。これらのサムネイルの1つがプッシュされると、ユーザーには、ビデオを表示するために作成したカスタムビデオプレーヤーを含む新しいビューが表示されます。
これは問題なく機能しますが、たまにしか機能しません。面白いことに、ユーザーが新しいビデオを正確に5回選択すると(つまり、新しいビューが表示され、新しいカスタムビデオプレーヤーオブジェクトが初期化されます)、プレーヤーからのビジュアルを表示するために使用される基になるAVPlayerLayerは黒くなりますが、基になるアセットがまだ正しく読み込まれているようです(プレーヤーインターフェイスは、ビデオの正しい継続時間などを保持しています)。
新しいカスタムメディアプレーヤーオブジェクトが初期化されると(これは、ビューを含むメディアプレーヤーのビューコントローラーがロードされるときに発生します)、これはAVPlayerとそれに関連するアイテムをセットアップする初期化メソッドの一部です。
// Start to load the specified asset
mediaAsset = [[AVURLAsset alloc] initWithURL:contentURL options:nil];
if (mediaAsset == nil)
NSLog(@"The media asset is zero!!!");
// Now we need to asynchronously load in the tracks of the specified asset (like audio and video tracks). We load them asynchronously to avoid having the entire app UI freeze while loading occours
NSString* keyValueToLoad = @"tracks";
// When loading the tracks asynchronously we also specify a completionHandler, which is the block of code that should be executed once the loading is either or for some reason failed
[mediaAsset loadValuesAsynchronouslyForKeys:[NSArray arrayWithObject:keyValueToLoad
] completionHandler:^
{
// When this block gets executed we check for potential errors or see if the asset loaded successfully
NSError* error = nil;
AVKeyValueStatus trackStatus = [mediaAsset statusOfValueForKey:keyValueToLoad error:&error];
if (error != nil)
{
NSLog(@"Error: %@", error.description);
}
//switch (trackStatus) {
//case AVKeyValueStatusLoaded:
if (trackStatus == AVKeyValueStatusLoaded)
{
NSLog(@"Did load properly!");
mediaItem = [AVPlayerItem playerItemWithAsset:mediaAsset];
if (mediaItem.error == nil)
NSLog(@"Everything went fine!");
if (mediaItem == nil)
NSLog(@"THE MEDIA ITEM WAS NIL");
[mediaItem addObserver:self forKeyPath:@"status" options:0 context:&itemStatusContext];
mediaContentPlayer = [[AVPlayer alloc] initWithPlayerItem:mediaItem];
[mediaContentView setPlayer:mediaContentPlayer];
//mediaContentView = [AVPlayerLayer playerLayerWithPlayer:mediaContentPlayer];
[activeModeViewBlocked configurePlaybackSliderWithDuration:mediaItem.duration];
originalDuration = mediaItem.duration.value / mediaItem.duration.timescale;
// We will subscribe to a timeObserver on the player to check for the current playback time of the movie within a specified interval. Doing so will allow us to frequently update the user interface with correct information
playbackTimeObserver = [mediaContentPlayer addPeriodicTimeObserverForInterval:CMTimeMake(1, 50) queue:dispatch_get_main_queue() usingBlock:^(CMTime time)
{
NSLog(@"TIME UPDATED!");
[activeModeViewBlocked updatePlaybackSlider:time];
}];
[self syncUI];
}
if (trackStatus == AVKeyValueStatusFailed)
{
NSLog(@"Something failed!");
}
if (trackStatus == AVKeyValueStatusCancelled)
{
NSLog(@"Something was cancelled!");
}
}];
このカスタムメディアプレーヤーオブジェクトを正確に5回初期化すると、常に黒い画面のレンダリングが開始されます。
なぜこれが起こっているのか誰かが知っていますか?