[英]iOS AVPlayer does not start playing
Its simple: My video player shows up, but never plays anything. 很简单:我的视频播放器出现了,但是什么也没播放。 The file I am trying to play exist already (checked).
我要播放的文件已经存在(已选中)。 I am just starting with a new "Single View" project.
我只是从一个新的“单视图”项目开始。
#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
Use below written code just before executing play statement. 在执行play语句之前,请使用以下编写的代码。
_player.numberOfLoops=0;
_player.delegate=self;
[_player prepareToPlay];
.ts
extension not works with ios. .ts
扩展名不适用于ios。 try some other extension videos ie. 尝试其他一些扩展视频,即。
.mp4
. .mp4
。 if problem arises then try to use [_player prepareToPlay]
; 如果出现问题,请尝试使用
[_player prepareToPlay]
;
try this one- Convert your url into NSdata 试试这个- 将您的网址转换为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];
hope it will help u 希望对你有帮助
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.