他の誰かが書いたプロジェクトを手に入れました。プロジェクトはこのパスにビデオファイルを保存します、file://localhost/var/mobile/Applications/CAC8F2CB-1C7D-4805-BF1A-42B63B258E95/Documents/output.mp4
MPMoviePlayerControllerでファイルを再生したいのですが、どうすればファイルにアクセスできますか?
他の誰かが書いたプロジェクトを手に入れました。プロジェクトはこのパスにビデオファイルを保存します、file://localhost/var/mobile/Applications/CAC8F2CB-1C7D-4805-BF1A-42B63B258E95/Documents/output.mp4
MPMoviePlayerControllerでファイルを再生したいのですが、どうすればファイルにアクセスできますか?
パスとファイルのURLを最初にロードします。
NSString *documentsDirectory = [NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES) objectAtIndex:0];
NSString *localFilePath = [photoDirectoryPath stringByAppendingPathComponent:@"output.mp4"];
次に、MPMoviePlayerControllerにURLをロードします
- (void)initMoviePlayer
{
didExit = NO;
[[NSNotificationCenter defaultCenter] addObserver:self
selector:@selector(moviePreloadDidFinish:)
name:MPMoviePlayerLoadStateDidChangeNotification
object:mMoviePlayer];
[[NSNotificationCenter defaultCenter] addObserver:self
selector:@selector(moviePlayBackDidFinish:)
name:MPMoviePlayerPlaybackDidFinishNotification
object:nil];
NSLog(@"initMoviePlayer: %@ ",[self getMovieURL]);
mMoviePlayer = [[MPMoviePlayerController alloc] initWithContentURL:[self getMovieURL]];
mMoviePlayer.shouldAutoplay = YES;
mMoviePlayer.view.hidden = YES;
[mMoviePlayer setControlStyle:MPMovieControlStyleNone];
mMoviePlayer.view.frame = [self.view bounds];
mMoviePlayer.scalingMode = MPMovieScalingModeNone;
[[self view] addSubview:[mMoviePlayer view]];
[mMoviePlayer play];
}
- (void) moviePreloadDidFinish:(NSNotification*)notification {
// start playing the movie
mMoviePlayer.view.hidden = NO;
animateTimer = [NSTimer scheduledTimerWithTimeInterval:0.5
target:self
selector:@selector(playMovie:)
userInfo:nil
repeats:NO];
}
- (void) moviePlayBackDidFinish:(NSNotification*)notification
{
}
上記のURLをどこかに保存しておけば
NSString *fullURL = @"/var/mobile/Applications/CAC8F2CB-1C7D-4805-BF1A-42B63B258E95/Documents/output.mp4"
NSURL *movieURL = [NSURL fileURLWithPath: isDirectory:YES]; //If YES not works use NO
MPMoviePlayerController *player = [[MPMoviePlayerController alloc] initWithContentURL:movieURL];
それが役立つことを願っています
これを試して :-
NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);
NSString *documentsDirectory = [paths objectAtIndex:0];
NSString *fullPath = [documentsDirectory stringByAppendingPathComponent:@"output.mp4"];
ここに、fullPath
上記のパスがあります。
ビデオの再生方法の詳細については、このチュートリアルを参照してください
これがあなたに役立つことを願っています..
このコードメイトを試してみてください。
NSString *documentDirectory = [NSSearchPathForDirectoriesInDomains(NSDocumentDirectory,NSUserDomainMask, YES) objectAtIndex:0];
NSString *videoFilePath = [documentDirectory stringByAppendingPathComponent:@"output.mp4"];
NSURL *videoURL = [NSURL URLWithString:videoFilePath];
MPMoviePlayerController *moviePlayer = [[MPMoviePlayerController alloc] initWithContentURL:videoURL];