avurlassetは正しく初期化されますが、関連するavplayerlayerが黒くするだけです

StackOverflow https://stackoverflow.com/questions/9346347

質問

ユーザーがローカルビデオファイルから選択できるアプリケーションがあります。これらのサムネイルの1つがプッシュされると、ユーザーはビデオを提示したカスタムビデオプレーヤーを備えた新しいビューを提示されます。

これは完璧に機能しますが、それだけです 時折. 。おもしろいのは、ユーザーが新しいビデオを選択し(したがって、新しいビューが表示され、新しいカスタムビデオプレーヤーオブジェクトの初期化)正確に5回選択した場合、プレーヤーのビジュアルをブラックレンダリングするために使用される基礎となるAvplayerLayer基礎となる資産はまだ正しくロードされているようです(プレーヤーインターフェイスは、ビデオの正しい期間などを保持しています)。

新しいカスタムメディアプレーヤーオブジェクトが初期化されると(これは、ビューを含むメディアプレーヤーのビューコントローラーがロードされたときに発生します)、これはAVPlayerとその関連アイテムをセットアップするInitializerメソッドの一部です。

    // 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回初期化すると、常に黒い画面のレンダリングが開始されます。

なぜこれが起こっているのかという考えはありますか?

役に立ちましたか?

解決

これも私です。 AVFoundationが許可する同時ビデオプレーヤーの数には制限があります。その数は4です(iOS 4.xの場合、最近では数が増加したようです。たとえば、iOS 7では、1つの画面に最大8つの画面がありませんでした)。それが5番目のもので黒くなっている理由です。他のアプリには「レンダリングパイプライン」が必要になる可能性があるため、4つを取得するとは思いません。

このAPIは、レンダリングパイプラインを引き起こします。

+[AVPlayer playerWithPlayerItem:]
ライセンス: CC-BY-SA帰属
所属していません StackOverflow
scroll top