开发者

iphone: video playing with sound only.video is not being viewed

开发者 https://www.devze.com 2023-03-18 02:36 出处:网络
this is the function through which i am playing my video.but it only plays sound,video is not being viewed

this is the function through which i am playing my video.but it only plays sound,video is not being viewed

  -(void)playMovieAtURL:(NSString *)moviePath
    {   
        NSURL *movieURL=[NSURL URLWithString:moviePath];

        MPMoviePlayerController *player = [[MPMoviePlayerController alloc] initWithContentURL:movieURL];

        NSLog(@"url : %@",movieURL);

        [player setControlStyle:MPMovieControlStyleDefault];

        [player setScalingMode:MPMovieScalingModeAspectFit开发者_Python百科];

        [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(movieDidExitFullscreen:) name:MPMoviePlayerPlaybackDidFinishNotification object:player];

        [[player view]setFrame:[[self view]bounds]];
        [[self view] addSubview:[player view]];

        [player play];

    }


MPMoviePlayerController is simply a movie player, it does not actually handle displaying the movie, if that makes sense. You should only use MPMoviePlayerController if you need to embed the video into your own view hierarchy. It doesn't sound like you need to do that since you're playing it fullscreen and you made mention of custom controls, so instead, try using MPMoviePlayerViewController. It does everything you need to load a movie from URL and display the video with native controls. Simply instantiate MPMoviePlayerViewController with your URL and present it as a modal view, i.e.

MPMoviePlayerViewController *player = [[MPMoviePlayerViewController alloc]initWithContentURL:[NSURL urlWithString:moviePath]];
[self presentModalViewController:player];
[player release];
0

精彩评论

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

关注公众号