user2115342
user2115342

Reputation: 31

How to play video using Mediaplayer framework in ios?

here i want to play a youtube video using mediaplayer framework.For this i follow this process, 1)I am adding mediaplayer framework. 2)I am importing #import header file 3)I implemented code by using google

But it shows thread ,

Can any one tell me how to solve this problem.

Upvotes: 3

Views: 6461

Answers (2)

Dharmbir Singh
Dharmbir Singh

Reputation: 17535

Please try thie one .. i think this one may your help.

- (IBAction)playVideo:(id)sender
{    
    NSURL *videosURL = [NSURL URLWithString:@"YourVideoURL"];
    MPMoviePlayerController *moviePlayController = [[MPMoviePlayerController alloc]initWithContentURL:videosURL];
    [self.view addSubview:moviePlayController.view];

    [moviePlayController prepareToPlay];
    moviePlayController.controlStyle = MPMovieControlStyleDefault;
    moviePlayController.shouldAutoplay = YES;
    [moviePlayController setFullscreen:YES animated:YES];
}

- (void) moviePlayBackDidFinish:(NSNotification*)notification
{

    MPMoviePlayerController *player = [notification object];

    [[NSNotificationCenter defaultCenter] removeObserver:self
                                                    name:MPMoviePlayerPlaybackDidFinishNotification object:player];

    if ([player respondsToSelector:@selector(setFullscreen:animated:)])
    {
        [player.view removeFromSuperview];
    }
}

Upvotes: 1

Related Questions