2011-09-22 142 views
-1

現在我在這裏提出與MPMoviePlayer有關的新問題。我有一個桌面視圖,在ipad的一側列出視頻,在另一側 - 我播放列表中選擇的視頻。這些發生在同一視圖中。現在切換到不同的視頻效果很好。現在,當我使用UIVideoEditorController編輯視頻時,我將替換文檔文件夾中的當前視頻文件,然後再次播放視頻。但後來我的球員停止工作...使用MPMoviePlayer播放視頻

我認爲問題是UIVideoEditorController內的球員沒有正確發佈。我發佈了編輯器,但還是我只是有..沒有什麼作品AGAIN :(

請幫我儘快

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

}

當編輯器返回SUC這種方法被稱爲cessfully。 此後我的視頻不播放

回答

0

最後我解決了問題,在另一個視圖控制器中使用UIVideoEditorController,然後延遲播放視頻的秒級。可能發生這種情況是因爲我試圖播放正在被替換的視頻。