1

In my application I play video on one of the view which contains following code

NSURL *url = [NSURL fileURLWithPath:[[NSBundle mainBundle] pathForResource:@"bgVideo" ofType:@"mov"]];
        player = [[MPMoviePlayerController alloc] initWithContentURL:url];

        [player setControlStyle:MPMovieControlStyleNone];
        player.view.frame = CGRectMake(35, 190, 245, 156);
        [self.view addSubview:player.view];
        [player play];
        [player.view setBackgroundColor:[UIColor clearColor]];

I wrote this code on viewWillAppear method

but when I come to this view initially my MPMoviePlayerController shows black screen before starting the video for fraction of second.

I don't want black screen for second.

what shoud I do for it?

thanx in advance.

kEvin
  • 411
  • 6
  • 18
  • related: http://stackoverflow.com/questions/8429701/mpmovieplayercontroller-showing-black-empty-screen – bummi Oct 20 '13 at 12:36

1 Answers1

0

maybe player a strong property and synthesize it. It worked.

should work in your case as well.

My experience, will not problem any more. Please reply if you can not work.


Edit

I had a little mistaken.

Black screen is shown before the start, because the video is not loaded.

you can not predict the time taken to loading the video. Even if you allocate player to viewWillApper method. black screen will appear. This black screen can not control it. YouTube app, or a default video App also same. In During a Black screen, ActivityIndicator or "Loading" message should show to user. It is reasonable. Finally In general, the larger the video size and quality, takes longer to load. if you want exactly loading time, you should be notified.

refer a sample code.

- (void)viewWillAppear:(BOOL)animated
{
    NSURL *url = [NSURL fileURLWithPath:[[NSBundle mainBundle] pathForResource:@"Movie" ofType:@"m4v"]];
    player = [[MPMoviePlayerController alloc] initWithContentURL:url];

    [player setControlStyle:MPMovieControlStyleNone];
    player.view.frame = CGRectMake(35, 190, 245, 156);
    [self.view addSubview:player.view];
    [player.view setBackgroundColor:[UIColor clearColor]];
    player.shouldAutoplay = NO;
    [player prepareToPlay];

    [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(loadMoviePlayerStateChanged:)
                                                 name:MPMoviePlayerLoadStateDidChangeNotification
                                               object:self.player];

    [super viewWillAppear:animated];
}

- (void)loadMoviePlayerStateChanged:(NSNotification *)noti
{
    int loadState = self.player.loadState;
    if(loadState & MPMovieLoadStateUnknown)
    {
        NSLog(@"MPMovieLoadStateUnknown");
        return;
    }
    else if(loadState & MPMovieLoadStatePlayable)
    {
        NSLog(@"MPMovieLoadStatePlayable");
        [player play];
    }
    else if(loadState & MPMovieLoadStatePlaythroughOK)
    {
        NSLog(@"MPMovieLoadStatePlaythroughOK");
    } else if(loadState & MPMovieLoadStateStalled)
    {
        NSLog(@"MPMovieLoadStateStalled");
    }
}
bitmapdata.com
  • 9,572
  • 5
  • 35
  • 43
  • @property (strong, nonatomic) MPMoviePlayerController *player; I write this code but it causes same problem. – kEvin Aug 01 '12 at 12:03