简单:我的视频播放器显示,但从不播放任何内容。我正在尝试播放的文件已经存在(已选中)。 我刚刚开始一个新的“单一视图”项目。
#import "ViewController.h"
#import <MediaPlayer/MediaPlayer.h>
@interface ViewController ()
@property (nonatomic, strong) MPMoviePlayerController *player;
@end
@implementation ViewController
- (void)viewDidAppear:(BOOL)animated
{
[super viewDidAppear:animated];
NSString *documentsDirectory = [NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES) objectAtIndex:0];
NSString *filepath = [NSString stringWithFormat:@"%@/Videos/fileSequence0.ts", documentsDirectory];
NSLog(@"!! %i", [[NSFileManager defaultManager] fileExistsAtPath:filepath]);
NSURL *fileURL = [NSURL fileURLWithPath:filepath];
_player = [[MPMoviePlayerController alloc] initWithContentURL:fileURL];
[_player.view setFrame: CGRectMake(0, 0, 500, 500)];
[self.view addSubview:_player.view];
[_player play];
}
@end
答案 0 :(得分:0)
在执行播放声明之前使用以下编写的代码。
_player.numberOfLoops=0;
_player.delegate=self;
[_player prepareToPlay];
答案 1 :(得分:0)
.ts
扩展程序不适用于ios。尝试一些其他的扩展视频即。 .mp4
。如果出现问题,请尝试使用[_player prepareToPlay]
;
答案 2 :(得分:0)
尝试这一个 - 将您的网址转换为NSdata
NSString* resourcePath = self.audioStr; //your video file formet should be .mp4
NSData *_objectData = [NSData dataWithContentsOfURL:[NSURL URLWithString:resourcePath]];
NSError *error = [[NSError alloc] init];
NSLog(@"url is %@",resourcePath);
_player = [[MPMoviePlayerController alloc] initWithData:_objectData error:&error];
[_player.view setFrame: CGRectMake(0, 0, 500, 500)];
[_player prepareToPlay];
_player.controlStyle = MPMovieControlStyleFullscreen;
_player.shouldAutoplay = NO;
[_player setFullscreen:YES animated:YES];
[self.view addSubview:_player.view];
[_player play];
希望它会帮助你