【发布时间】:2011-04-28 12:29:32
【问题描述】:
我想从应用程序中在 iPhone 中播放 Youtube 视频。我尝试使用 MPMoviePlayerController,但没有加载视频。它正在播放我从捆绑包中加载的视频,而不是你的管视频。我还尝试通过将 Youtube 视频嵌入到 UIWebView 中来播放它,但这也是徒劳的。任何人都可以建议我一个我应该采取的方法。我在 IOS 4.2 中测试它
这是我使用的代码。
mp = [[MPMoviePlayerController alloc] initWithContentURL:movieURL];
if ([mp respondsToSelector:@selector(loadState)])
{
// Set movie player layout
[mp setControlStyle:MPMovieControlStyleFullscreen];
[mp setFullscreen:YES];
// May help to reduce latency
[mp prepareToPlay];
// Register that the load state changed (movie is ready)
[[NSNotificationCenter defaultCenter] addObserver:self
selector:@selector(moviePlayerLoadStateChanged:)
name:MPMoviePlayerLoadStateDidChangeNotification
object:nil];
}
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];
【问题讨论】:
标签: ios ios4 uiwebview media-player