2013-05-29 62 views
0

其簡單:我的視頻播放器出現,但從來沒有播放任何東西。我試圖播放的文件已存在(選中)。 我剛剛開始一個新的「單一視圖」項目。iOS AVPlayer不開始玩

#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

是.ts能夠與ios一起玩 – iEinstein

+0

@WillJenkins您不必合成,除非您想重命名合成屬性。 –

回答

0

在執行播放語句之前使用下面的書面代碼。

_player.numberOfLoops=0; 
    _player.delegate=self; 
    [_player prepareToPlay]; 
+0

根本沒有這樣的屬性。 –

0

.ts擴展名不適用於ios。嘗試一些其他的擴展視頻即。 .mp4。如果問題出現,請嘗試使用[_player prepareToPlay];

+0

.ts的作品。至少在另一個項目中(相同的視頻文件)。 –

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

希望如果您使用的是屬性,你也應該合成它在您的實現也將幫助ü

+0

如果有任何查詢請求? –