开发者

open the youtube link thorugh my application without webview

开发者 https://www.devze.com 2023-03-02 18:42 出处:网络
I am using this code so that youtube video will display without webview -(IBAction) trailor { //declaring path to file and stuff...

I am using this code so that youtube video will display without webview

-(IBAction) trailor {

    //declaring path to file and stuff...

    NSString *urlAddress = self.Trailor;//@"http://www.youtube.com/watch?v=FZXcWK0tZjc&feature=related";

    NSLog(@"url %@",urlAddress);
    NSURL *url = [NSURL URLWithString:urlAddress]; 



    MPMoviePlayerViewController *playerViewController = [[MPMoviePlayerViewController alloc] initWithContentURL:url   ];

    [[NSNotificationCenter defaultCenter] addObserver:self
                                             selector:@selector(moviePlayBackDidFinish:)
                                                 name:MPMoviePlayerPlaybackDidFinishNotification
                                               object:[playerViewController moviePlayer]];

    [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(moviePlayBackDidFinish:) name:MPMoviePlayerPlaybackDidFinishNotification object:[playerViewController moviePlayer]];      

    MPMoviePlayerController *player = [playerViewController moviePlayer];
    [self.view addSubview:playerViewController.view];
    player.controlStyle = MPMovieControlStyleDefault;
    player.shouldAutoplay = YES;
    [player setFullscreen:YES animated:YES];
} 


- (void)moviePlayBackDidFinish:(NSNotification*)notification {
    MPMoviePlayerViewController *moviePlayer = [notification object];
    [[NSNotificationCenter defaultCenter] removeObserver:self
                                                    name:MPMoviePlayerPlaybackDidFinishNotification
            开发者_如何学编程                                      object:moviePlayer];

    [moviePlayer.view removeFromSuperview];
    //[self.view setHidden:NO];


    [moviePlayer release];  
}

but there is no any reponse from this code, when I run this code thorugh a button.. it will

open the youtube link thorugh my application without webview

it will display me only this screen and nothing else.

I want to open youtube link thorugh my app without using webview how can I do it

any sample code? or tutorial you have then plz share it to me


There are similar (if not same ) questions out there.
youtube donot give direct access to video (which MPMoviePlayerViewController expects). hence it cant play the youtube videos directly (using initWithContentURL).

The only method is to play Youtube videos in your app is through UIWebView. see How to Play Youtube video in webview in iphone? to get better idea on how to.

0

精彩评论

暂无评论...
验证码 换一张
取 消