NSString *path = [[NSBundle mainBundle] pathForResource:@"PTCL" ofType:@"mp4"];
NSURL *videoURL = [NSURL URLWithString:path];
MPMoviePlayerController *moviePlayerController = [[MPMoviePlayerController alloc] initWithContentURL:videoURL];
[moviePlayerController.view setFrame:self.view.frame];
[self.view addSubview:moviePlayerController.view];
moviePlayerController.controlStyle=MPMediaTypeAnyVideo;
moviePlayerController.fullscreen = YES;
[moviePlayerController prepareToPlay];
[moviePlayerController play];
NSString *path = [[NSBundle mainBundle] pathForResource:@"PTCL" ofType:@"mp4"];
path=[NSString stringWithFormat:@"file:/%@",path];
NSURL *videoURL = [NSURL URLWithString:path];
MPMoviePlayerController *moviePlayerController = [[MPMoviePlayerController alloc] initWithContentURL:videoURL];
[moviePlayerController.view setFrame:self.view.frame];
[self.view addSubview:moviePlayerController.view];
moviePlayerController.shouldAutoplay=YES;
moviePlayerController.controlStyle=MPMediaTypeAnyVideo;
moviePlayerController.fullscreen = YES;
[moviePlayerController prepareToPlay];
[moviePlayerController play];
我正在获取第一个代码的videURL路径
我正在获取第二个代码的videURL路径。
我有alos使用
NSURL *videoURL = [[NSURL alloc]init];
videoURL = [[NSBundle mainBundle] URLForResource:@"PTCL" withExtension:@"mp4"];
但我的视频播放器总是显示文件正在加载,没有任何反应。 我知道一些我在做错的地方,但我的运气不好。 请更正我的错误或告诉我是否有其他方式播放本地视频文件。请。
答案 0 :(得分:4)
也许为时已晚,但我会尝试类似的事情:
MPMoviePlayerViewController *movieVC = [[MPMoviePlayerViewController alloc] initWithContentURL:file.location];
movieVC.moviePlayer.movieSourceType = MPMovieSourceTypeFile;
movieVC.moviePlayer.fullscreen = YES;
movieVC.moviePlayer.allowsAirPlay = YES;
movieVC.moviePlayer.controlStyle = MPMovieControlStyleFullscreen;
[self presentMoviePlayerViewControllerAnimated:movieVC];
注意“movieVC.moviePlayer.movieSourceType = MPMovieSourceTypeFile;”
答案 1 :(得分:2)
我改用了这个简单的解决方案:
NSURL *url = [NSURL fileURLWithPath:[[NSBundle mainBundle] pathForResource:@"video" ofType:@"mp4"]];
MPMoviePlayerViewController* viewController = [[MPMoviePlayerViewController alloc] initWithContentURL:url];
[self presentMoviePlayerViewControllerAnimated:viewController];
答案 2 :(得分:2)
NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory,NSUserDomainMask, YES);
NSString *documentsDirectory = [paths objectAtIndex:0];
NSString *dataPath = [documentsDirectory stringByAppendingPathComponent:@"CapturedMedia"];
NSString *filePath = [dataPath stringByAppendingPathComponent:@"/itemVideo.mp4"];
_moviePlayer =[[MPMoviePlayerViewController alloc] initWithContentURL:[NSURL fileURLWithPath:filePath]];
[[_moviePlayer view] setFrame:[[self view] bounds]];
[[_moviePlayer moviePlayer] prepareToPlay];
[[_moviePlayer moviePlayer] setShouldAutoplay:YES];
[[_moviePlayer moviePlayer] setControlStyle:2];
[[_moviePlayer moviePlayer] setRepeatMode:MPMovieRepeatModeNone];
[self presentMoviePlayerViewControllerAnimated:_moviePlayer];
在.h文件中设置MPMoviePlayerViewController的属性。
答案 3 :(得分:2)
MPMoviePlayerController
现已弃用。所以我使用了AVPlayerViewController
。并编写以下代码:
NSURL *videoURL = [NSURL fileURLWithPath:filePath];
AVPlayer *player = [AVPlayer playerWithURL:videoURL];
AVPlayerViewController *playerViewController = [AVPlayerViewController new];
playerViewController.player = player;
//[playerViewController.player play];//Used to Play On start
[self presentViewController:playerViewController animated:YES completion:nil];
请不要忘记导入以下框架:
#import <AVFoundation/AVFoundation.h>
#import <AVKit/AVKit.h>
希望这有助于......
答案 4 :(得分:0)
您的电影播放器代码看起来很好。路径有问题。只是尝试明确地转到路径。并检查该文件是否存在。您可以看到以下SO问题供您参考:
答案 5 :(得分:0)
游戏稍晚,但这是我的完整代码
在* .h
Pattern pattern = Pattern.compile(".*(?:finger|ground)_5.*");
System.out.println(String.format("%s = %s", "finger_5_ground_4_phase_92", pattern.matcher("finger_5_ground_4_phase_92").matches() ? "YES" : "NO"));
System.out.println(String.format("%s = %s", "finger_1_ground_2_phase_9", pattern.matcher("finger_1_ground_2_phase_9").matches() ? "YES" : "NO"));
System.out.println(String.format("%s = %s", "finger_4_ground_2_phase_5", pattern.matcher("finger_4_ground_2_phase_5").matches() ? "YES" : "NO"));
System.out.println(String.format("%s = %s", "finger_4_ground_2_env_5", pattern.matcher("finger_4_ground_2_env_5").matches() ? "YES" : "NO"));
System.out.println(String.format("%s = %s", "finger_4_ground_5_env_5", pattern.matcher("finger_4_ground_5_env_5").matches() ? "YES" : "NO"));
在* .m
@interface v1SupportTable : UITableViewController
{
MPMoviePlayerController *moviePlayer1;
}