Search code examples
iosobjective-ciphonempmovieplayercontrollermpmovieplayer

iOS - Video looping not working on iphone 4


I am using MPMoviePlayer to play video in my iPhone application.

I want play video in loop means wants to play single video repeatedly.

I am using following code to repeat the video:

MoviePlayer.repeatMode = MPMovieRepeatModeOne;

It is working properly on Simulator and higher phone But it is not working properly on iPhone 4.

It is not repeating the video on iPhone 4 Device

Is there any specific reason for that? is there any solution for that?

My iPhone is iPhone 4 with updated iOS 7

Thank you


Solution

  • This Solution I have implemented:

    I have used MPMoviePlayerPlaybackStateDidChangeNotification this Notification

    Added following notification to Movie Player

    [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(moviePlayBackDidFinishedFromSetUnderway:) name:MPMoviePlayerPlaybackStateDidChangeNotification object:MoviePlayer];
    

    Notification Method:

    -(void)moviePlayBackDidFinishedFromSetUnderway:(NSNotification *)dict{
    
        if (dict.object == MoviePlayer) {
            NSInteger reason = [[dict.userInfo objectForKey:MPMoviePlayerPlaybackDidFinishReasonUserInfoKey] integerValue];
            if (reason == MPMovieFinishReasonPlaybackEnded)
            {
                [MoviePlayer prepareToPlay];
                [MoviePlayer play];
            }
        }
    }
    

    Done !!! It is working properly now ... :)