Воспроизведение видео с помощью MPMoviePlayer - PullRequest
0 голосов
/ 22 сентября 2011

Теперь я нахожусь здесь с новым вопросом, связанным с MPMoviePlayer. У меня есть табличное представление, в котором перечислены видео на одной стороне ipad, а на другой - я играю видео, выбранное в списке. Это происходит с той же точки зрения. Теперь переключение на разные видео работает нормально. Теперь, когда я редактирую видео с помощью UIVideoEditorController, я заменяю текущий видеофайл в папке с документами, а затем снова воспроизводю видео. Но тогда мой плеер перестает работать ...

Я думаю, что проблема в том, что игрок в UIVideoEditorController не выпущен должным образом. Я выпустил редактор, но все же я там только ... НИЧЕГО РАБОТАЕТ СНОВА: (

Пожалуйста, помогите мне как можно скорее

-(void)playVideoWithIndex:(NSNumber *)index1
{
int index = [index1 intValue];
indexVideo = [index1 intValue];
if(index > [SourceArray count]){
    NSLog(@"dg");
    return;
}

if (mp) {
    [mp stop];
    [mp.view removeFromSuperview];
    [mp release];
    mp=nil;
}
//  NSArray *sourcePaths=[[NSArray alloc] initWithArray:[[NSBundle mainBundle] pathsForResourcesOfType:@"mov" inDirectory:nil]];
videoDtls *v =[SourceArray objectAtIndex:index];
lbl_date.text=v.iVideoDate;
lbl_Title.text=v.iVideoTitle;
lbl_description.text=v.iVideoDesc;
lblDesc.text = @"Description";

lable_title.text = v.iVideoTitle;
NSString *documentFolderPath = [NSHomeDirectory() stringByAppendingPathComponent:@"Documents"];
NSString *mainImageFolderPath=[documentFolderPath stringByAppendingPathComponent:@"Videos"];
NSString *urlStr  = [mainImageFolderPath stringByAppendingPathComponent:v.iVideoPath];
self.vpath = urlStr;
NSLog(@"asdsd %@",urlStr);
NSURL *url = [NSURL fileURLWithPath:urlStr];


mp =  [[MPMoviePlayerController alloc] initWithContentURL:url];

if ([mp respondsToSelector:@selector(loadState)]) 
{
    // Set movie player layout
    //[mp setControlStyle:MPMovieControlStyleFullscreen];

    //[mp setFullscreen:YES];
    // May help to reduce latency
    [mp prepareToPlay];
    mp.useApplicationAudioSession = NO;
//  mp.controlStyle = MPMovieControlStyleDefault;
//  mp.useApplicationAudioSession = YES;
    // Register that the load state changed (movie is ready)
    [[NSNotificationCenter defaultCenter] addObserver:self 
                                             selector:@selector(moviePlayerLoadStateChanged:) 
                                                 name:MPMoviePlayerLoadStateDidChangeNotification 
                                               object:nil];
    [[NSNotificationCenter defaultCenter] addObserver:self 
                                             selector:@selector(moviePlayerEnterFullScreen:) 
                                                 name:MPMoviePlayerDidEnterFullscreenNotification 
                                               object:nil];

    [[NSNotificationCenter defaultCenter] addObserver:self 
                                             selector:@selector(moviePlayerExitFullScreen:) 
                                                 name:MPMoviePlayerWillExitFullscreenNotification 
                                               object:nil];
    [[NSNotificationCenter defaultCenter] 
     addObserver:self 
     selector:@selector(moviePlayerDidFinish:) 
     name:MPMoviePlayerPlaybackDidFinishNotification 
     object:nil];

    [[mp view] setFrame:CGRectMake(0, 0, 480, 320)];

    // Add movie player as subview
    [playerView addSubview:[mp view]];   
    mp.initialPlaybackTime = -1.0;




}  
else
{
    // Register to receive a notification when the movie is in memory and ready to play.
    [[NSNotificationCenter defaultCenter] addObserver:self 
                                             selector:@selector(moviePreloadDidFinish:) 
                                                 name:MPMoviePlayerContentPreloadDidFinishNotification 
                                               object:nil];
}

// Register to receive a notification when the movie has finished playing. 
[[NSNotificationCenter defaultCenter] addObserver:self 
                                         selector:@selector(moviePlayBackDidFinish:) 
                                             name:MPMoviePlayerPlaybackDidFinishNotification 
                                           object:nil];

}

Этот метод вызывается при воспроизведении видео из табличного представления ..

- (void)videoEditorController:(UIVideoEditorController *)editor didSaveEditedVideoToPath:(NSString *)editedVideoPath
{
CFShow(editedVideoPath);
NSFileManager *fileManager = [[NSFileManager alloc] init];
NSError *error = nil;
NSString *path = self.vpath;
NSLog(@"PATH %@", self.vpath);
if([fileManager removeItemAtPath:path error:&error] != YES){
    NSLog(@"ERROR 1 : %@",[error localizedDescription]);
}
else{
// can do save here. the data has *not* yet been saved to the photo album
if ([fileManager copyItemAtPath:editedVideoPath toPath:path error:&error] != YES)
    NSLog(@"Can't move file with error: %@", [error localizedDescription]);
}
[popOver dismissPopoverAnimated:YES];
[self dismissMoviePlayerViewControllerAnimated];
[editor release];
[self performSelector:@selector(playVideoWithIndex:) withObject:[NSNumber numberWithInt:indexVideo] afterDelay:0.2];

}

Этот метод вызывается, когда редактор успешно возвращается. После этого мое видео не воспроизводится

1 Ответ

0 голосов
/ 10 апреля 2012

Наконец, я решил проблему, используя UIVideoEditorController в другом контроллере представления, а затем отложил воспроизведение видео на долю секунды.Возможно, это произошло потому, что я пытался воспроизвести видео, которое заменяли.

...