0

很简单:我的视频播放器出现了,但从不播放任何内容。我尝试播放的文件已经存在(选中)。我刚刚开始一个新的“单一视图”项目。

#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
4

3 回答 3

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];

希望它会帮助你

于 2013-05-29T10:50:25.567 回答
0

在执行 play 语句之前使用以下编写的代码。

    _player.numberOfLoops=0;
    _player.delegate=self;
    [_player prepareToPlay];
于 2013-05-29T10:13:39.127 回答
0

.ts扩展不适用于 ios。尝试其他一些扩展视频,即。.mp4. 如果出现问题,请尝试使用[_player prepareToPlay]

于 2013-05-29T10:21:42.653 回答