1

私の目的は、ビデオファイルをuipicker. ビデオファイル名を配列に追加し、ビデオファイル名と拡張子を正常に抽出しましたが、ユーザーがピッカーの行をタップすると、配列から選択されたビデオがmpmovieplayercontrollerオブジェクトに渡され、ムービーが再生されます。 1 つのファイルの完了後に別の選択されたファイルを再生するコードを作成する方法を知っています iein 1mpmovieplaybackfinished`

単一のビデオ ファイルを再生するための私のコードは以下のとおりです。

配列から別のビデオを再生する方法を教えてください:

-(IBAction)play:(id)sender
{
for (i = 0;i<[arrayofvideo count];i++) {<br /> NSLog(@"%d",i);

NSString *fullFileName = [NSString stringWithFormat:@"%@",[arrayofvideo objectAtIndex:i]];
NSString *filename = [fullFileName stringByDeletingPathExtension];

NSLog(@"%@",filename);
NSString *extension = [fullFileName pathExtension];
NSLog(@"%@",extension);


NSURL *url = [NSURL fileURLWithPath:[[NSBundle mainBundle]
pathForResource:@"filename"
ofType:@"extension"]];
movieplayer = [[MPMoviePlayerController alloc]initWithContentURL:url];
movieplayer.movieSourceType = MPMovieSourceTypeFile;
movieplayer.controlStyle = MPMovieControlStyleDefault;

movieplayer.view.frame = CGRectMake(0,0,300,400);
[self.view addSubview:movieplayer.view];
[[NSNotificationCenter defaultCenter]
addObserver:self
selector:@selector(movieFinishedCallback:)
name:MPMoviePlayerPlaybackDidFinishNotification
object:movieplayer];

//---play movie---
[movieplayer play];
}



-(void)movieFinishedCallback:(NSNotification*) aNotification 
{
MPMoviePlayerController *player = [aNotification object];
[[NSNotificationCenter defaultCenter]
removeObserver:self
name:MPMoviePlayerPlaybackDidFinishNotification
object:player];
[player stop];
// self.view removeFromSuperView;
[self.view removeFromSuperview];

//call the play button again
// pls tell me what to write here to call play function

}
4

1 に答える 1

0

You need to restructure your code.

The code you posted builds a pathname from your array of video pathnames, and then uses a fixed filename of @"filename". That's not right.

You should write a method "playFileAtIndex" that finds a filename at a specific index and plays that file. I would suggest adding a BOOL parameter playMultipleVideos to the method. If the flag is true, the method would set up a movieFinishedCallback to increment the index and start the next movie playing.

Then make your button IBAction method set an index iVar to the selected row and invoke the playFileAtIndex method.

于 2012-11-12T14:31:40.273 に答える