播放

时间:2015-07-13 13:41:13

标签: ios objective-c video

完成播放后是否可以使视频不关闭?因此,这将允许用户按下"完成"视频完成后视频将关闭。

ViewController.h

#import <UIKit/UIKit.h>
#import <MediaPlayer/MediaPlayer.h>


@interface player1: UIViewController {
}

-(IBAction) playMovie;

@end

ViewController.m

#import "ViewController.h"

@implementation player1

-(IBAction) playMovie {

    NSURL *url = [NSURL fileURLWithPath:[[NSBundle mainBundle] pathForResource:@"2.DragtoopenfileinaVM" ofType:@"mp4"]];
    MPMoviePlayerViewController *windowsmac = [[MPMoviePlayerViewController alloc] initWithContentURL:url];
    [self presentMoviePlayerViewControllerAnimated:windowsmac];

    windowsmac.moviePlayer.movieSourceType = MPMovieSourceTypeFile;

    [windowsmac.moviePlayer play];

    windowsmac = nil;   

}

这是我正在使用的编码,有人可以帮忙吗?

1 个答案:

答案 0 :(得分:1)

 moviePlayer = [[MPMoviePlayerViewController alloc]initWithContentURL:[NSURL fileURLWithPath:path]];

[[NSNotificationCenter defaultCenter] removeObserver:moviePlayer

                                                name:MPMoviePlayerPlaybackDidFinishNotification

                                              object:moviePlayer.moviePlayer];

 [self presentViewController:moviePlayer animated:YES completion:nil];