Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7788373
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 1, 20262026-06-01T20:58:42+00:00 2026-06-01T20:58:42+00:00

I have an application in which the user can select from local video files.

  • 0

I have an application in which the user can select from local video files. When one of those thumbnails gets pushed, the user is presented a new view which have a custom video player I’ve made that presents the video.

This works flawlessly, but only sometimes. The funny thing is that if the user selects a new video (thus getting presented a new view, initializing a new custom video player object) exactly 5 times, the underlying AVPlayerLayer that is used to present the visuals from the player renders black, even though it seems like the underlying asset still loads correctly (the player interface still holds the correct duration for the video and so forth).

When a new custom media player object gets initialized (which happens when the view controller for the media players containing view gets loaded), this is the part of the initializer method which sets up the AVPlayer and its associated item:

    // 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!");
         }
     }];

Now if I initialize this custom media player object 5 times exactly, it always starts to render black screens.

Does anyone have any idea of why this could be happening?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-01T20:58:44+00:00Added an answer on June 1, 2026 at 8:58 pm

    This bit me too. There is a limit on the number of concurrent video players that AVFoundation will allow. That number is four(for iOS 4.x, more recently the number seems to have increased. For example, on iOS 7 I’ve had up to eight on one screen with no issue). That is why it is going black on the fifth one. You can’t even assume you’ll get four, as other apps may need a ‘render pipeline’.

    This API causes a render pipeline:

    +[AVPlayer playerWithPlayerItem:]
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have some option-item combination in my application from which the user can choose
I have an application, in which the user will select an image from a
i have created an application which show data from user current location. I want
I have an application in which I want to authenticate a user from a
I have a client application which runs as a Java applet from a user's
I have an application in which a user can pass in some or all
I have swing application in which there is MS excel like functionality. User can
I am developing a reporting application where a user can select(and order) reports from
In my application, I have a list of records. The user can select any
I have an application on which a user can create multiple profiles of three

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.