本地視頻播放

#import <MediaPlayer/MPMoviePlayerController.h>
 
- (void)playMovieAtURL:(NSURL*)theURL
{
    MPMoviePlayerController* theMovie= [[MPMoviePlayerController alloc] initWithContentURL:theURL];
    theMovie.scalingMode=MPMovieScalingModeAspectFill;
    //    theMovie.userCanShowTransportControls=NO;
 
    // Register for the playback finished notification.
    [[NSNotificationCenter defaultCenter] addObserver:self
                                            selector:@selector(myMovieFinishedCallback:)
                                                name:MPMoviePlayerPlaybackDidFinishNotification
                                              object:theMovie];
 
    // Movie playback is asynchronous, so this method returns immediately.
    [theMovie play];
}
 
// When the movie is done,release the controller.
- (void)myMovieFinishedCallback:(NSNotification*)aNotification
{
    MPMoviePlayerController* theMovie=[aNotification object];
    [[NSNotificationCenter defaultCenter] removeObserver:self
                                                    name:MPMoviePlayerPlaybackDidFinishNotification
                                                  object:theMovie];
 
    // Release the movie instance created in playMovieAtURL
    [theMovie release];
} 
 
- (void)video_play:(NSString*)filename
{
    NSString* s = [[NSBundle mainBundle] pathForResource:filename ofType:@"m4v"];
    NSURL* url = [NSURL fileURLWithPath:s];
    NSLog(@"Playing URL: %@", url);
    [self playMovieAtURL:url];
}
發佈了45 篇原創文章 · 獲贊 1 · 訪問量 15萬+
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章