2011-06-14 117 views
1

我有一個應用程序,允許用戶從媒體項目列表移動到使用向下鑽取表視圖模型的特定項目。需要幫助的MPMoviePlayerController初始化

Main View

一旦用戶詳細視圖內,另一個表視圖存在允許用戶選擇特定的媒體項目。

Detail View

我有創造一個模式的媒體播放器播放的MP4該項目的問題。下面的代碼是我到目前爲止。

if (indexPath.section == SectionHeader && indexPath.row == SectionHeaderEnclosure) { 
    if (item.enclosures) { 
     for (NSDictionary *dict in item.enclosures){ 

      NSString *url = [dict objectForKey:@"url"]; 
      NSLog(@" url is : %@",url); 

      //EXPERIMENTAL 
      MPMoviePlayerController *moviePlayer = [[MPMoviePlayerController alloc] initWithContentURL:url]; 

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

      if ([moviePlayer respondsToSelector:@selector(setFullscreen:animated:)]) { 
       // Use the 3.2 style API 
       moviePlayer.controlStyle = MPMovieControlStyleDefault; 
       moviePlayer.shouldAutoplay = YES; 
       [self.view addSubview:moviePlayer.view]; 
       [moviePlayer setFullscreen:YES animated:YES]; 
      } else { 
       // Use the 2.0 style API 
       moviePlayer.movieControlMode = MPMovieControlModeHidden; 
       [moviePlayer play]; 
      }   
     } 
    } 
} 

我需要這一行幫助: 的MPMoviePlayerController * moviePlayer = [[的MPMoviePlayerController頁頭] initWithContentURL:URL]。

它給我一個NSInvaild參數異常。我需要有關視頻播放器創建和隨後從視圖中刪除的幫助。

回答

2

它看起來像你有一個普通的NSString存儲的URL,而玩家期望NSURL。這個怎麼樣?

MPMoviePlayerController *moviePlayer = [[MPMoviePlayerController alloc] 
    initWithContentURL:[NSURL URLWithString:url]]; 
+0

非常感謝您!我的問題已解決! – 2011-06-14 15:49:14