【发布时间】:2014-01-13 04:29:34
【问题描述】:
我正在尝试循环播放本地视频,但我一直遇到问题。 iphone 模拟器构建将成功,但视频不会播放或循环。我正在制作一个在 LaunchImage 之后循环播放视频的应用程序。和MPMoviePlayerController有关系吗?
代码如下: ViewController.h
#import <UIKit/UIKit.h>
#import <MediaPlayer/MediaPlayer.h>
@interface ViewController : UIViewController
@end
ViewController.m
#import "ViewController.h"
@interface ViewController ()
@property (strong, nonatomic) MPMoviePlayerController *moviePlayer;
@end
@implementation ViewController
@synthesize moviePlayer;
- (void)viewDidLoad
{
[super viewDidLoad];
// Do any additional setup after loading the view, typically from a nib.
NSString*thePath=[[NSBundle mainBundle] pathForResource:@"ColoredDiamond" ofType:@".mp4"];
NSURL*theurl=[NSURL fileURLWithPath: thePath];
self.moviePlayer = [[MPMoviePlayerController alloc] initWithContentURL:theurl];
[self.moviePlayer.view setFrame:CGRectMake(40,197,240,160)];
[self.moviePlayer prepareToPlay];
[self.moviePlayer setShouldAutoplay:YES];
[self.view addSubview:self.moviePlayer.view];
[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(playBackFinished:) name:MPMoviePlayerPlaybackDidFinishNotification object:moviePlayer];
}
- (void)didReceiveMemoryWarning
{
[super didReceiveMemoryWarning];
// Dispose of any resources that can be recreated.
}
/* - (void) playbackFinished: (NSNotification*) notification{
NSLog(@"playBackFinished");
if(moviePlayer){
[moviePlayer play];
}
}
*/
@end
【问题讨论】:
标签: ios iphone objective-c video mpmovieplayer