2012年7月2日 星期一

在iOS 中, 如何使用 MediaPlayer 播放 URL 影片


-(void)doClick:(id)sender{
    //影片網址
    NSURL *url=[[NSURL alloc] initWithString:@"http://www.xxx.com/Aya1_8.mp4"];
    MPMoviePlayerViewController *playerViewController = 
    [[MPMoviePlayerViewController alloc
     initWithContentURL:url];
    
    playerViewController.moviePlayer.controlStyle = MPMovieControlStyleNone;
    playerViewController.moviePlayer.scalingMode = MPMovieScalingModeFill;
    
    [[NSNotificationCenter defaultCenter
     addObserver:self
     selector:@selector(myMovieFinishedCallback:)
     name:MPMoviePlayerPlaybackDidFinishNotification
     object:[playerViewController moviePlayer]];
    
    playerViewController.view.frame = [self view].frame;
    
    [[self view] addSubview:playerViewController.view];
    
    //---play movie---
    MPMoviePlayerController *player = [playerViewController moviePlayer];
    [player play];   
    
}

沒有留言:

張貼留言