2014-02-19 8 views
1

Я сохраняю видео по определенному пути в своем приложении.Загрузка видео из NSURL

т.е:

My Video Path is /private/var/mobile/Applications/57DBBE40-088E-48CD-AED7-9BDB8FF1E039/tmp/video_66C2B8C6-012C-4608-BA8C-97C7ABA0D721.mp4 

Я тогда пытался играть, что видео с помощью MPMoviePlayerController в пользовательском кадре.

videoPath = [stand stringForKey:@"videoPathKey"]; 
NSLog(@"My Video Path is %@", videoPath); 
    MPMoviePlayerController *player = [[MPMoviePlayerController alloc] initWithContentURL:[NSURL fileURLWithPath:videoPath]]; 
player.view.frame = CGRectMake(0, 44, 320, 272); 
[self.view addSubview:player.view]; 
[self.view bringSubviewToFront:player.view]; 
[player play]; 

Это не работает. Видео никогда не загружается. Любая идея почему?

И да, я получаю правильный видеоролик.

NSLog показывает это: URL файлов: ///private/var/mobile/Applications/57DBBE40-088E-48CD-AED7-9BDB8FF1E039/tmp/video_37794C4E-A3D0-4AC0-9964-A9DEBB61C3E2.mp4

+0

Проверьте, воспроизводится ли он в других видеоформатах, кроме mp4. – RAJA

ответ

0
NSString *urlStr = [[NSBundle mainBundle] pathForResource:@"Your VideoName" ofType:@"mp4"]; 
NSURL *url = [NSURL fileURLWithPath:urlStr]; 
mpMoviePlayerController = [[MPMoviePlayerController alloc] initWithContentURL:url]; 
mpMoviePlayerController.view.frame = CGRectMake(0, 0, self.playView.frame.size.width, self.playView.frame.size.height); 
[self.playView addSubview:mpMoviePlayerController.view]; 
[mpMoviePlayerController play]; 

попробуйте это!

+0

То, что у меня есть .... –

0

Это, как я сделал это в прошлом

- (MPMoviePlayerController *) loadFile:(NSString *) fileName intoView:(UIView*) videoView 
{ 
    NSString *thePath = [[NSBundle mainBundle] pathForResource:fileName ofType:@"mp4"]; 
    NSURL *theurl = [NSURL fileURLWithPath:thePath]; 
    MPMoviePlayerController *moviePlayer = [[MPMoviePlayerController alloc] initWithContentURL:theurl]; 
    [moviePlayer.view setFrame:videoView.bounds]; 
    [videoView addSubview:moviePlayer.view]; 
    [moviePlayer setControlStyle:MPMovieControlStyleNone]; 
    [moviePlayer setMovieSourceType:MPMovieSourceTypeFile]; 
    moviePlayer.shouldAutoplay = NO; 
    return moviePlayer; 
} 
0

Вы должны изменить URL, чтобы поместить схему:

NSURL *movieURL = [NSURL URLWithString:[NSString stringWithFormat:@"file://localhost%@",url]]; 

Ваше видео путь будет: файл://localhost/private/var/mobile/Applications/57DBBE40-088E-48CD-AED7-9BDB8FF1E039/tmp/video_66C2B8C6-012C-4608-BA8C-97C7ABA0D721.mp4

Я надеюсь, что помогает

Смежные вопросы