Search code examples
iphonevideouilabelmpmovieplayercontroller

How to show the current progress of the video played using MPMoviePlayer in a UILabel?


I need to show the current Progress of the video played using MPMoviePlayerController in a UILabel. I need to show the current progress and the total duration of the video in a UILable. It should look something like 1.25/5.00 ? I need to show this when the video is playing. I can show it directly with the Default Progress Bar but i need to disable it. As i am not able to disable it i am planning to show the current progress of the video in a UILabel. Can someone please provide any suggestion on this?


Solution

  • Got the Answer...

    When Instantiating the Video Player...

    self.moviePlayerController = [[MPMoviePlayerController alloc] initWithContentURL:fileURL];
    

    //Add the Label to show the Progress of the Video....

    progressLabel = [[UILabel alloc]initWithFrame:CGRectMake(125,275,70,25)];
    progressLabel.backgroundColor = [UIColor clearColor];
    [progressLabel setTextColor:[UIColor whiteColor]];
    [self.view addSubview:progressLabel];
    

    //set a Timer..

    [NSTimer scheduledTimerWithTimeInterval:1.0f 
                                     target:self 
                                   selector:@selector(updatePlaybackTime:) 
                                   userInfo:nil 
                                    repeats:YES];
    

    and in the Method updatePlaybackTime: ....

    - (void)updatePlaybackTime:(NSTimer*)theTimer {
        progressLabel.text = [NSString stringWithFormat:@"%f",self.moviePlayerController.currentPlaybackTime];
    }
    

    Done..U will have the Label updated with the progress of the Video...