使用 MPMoviePlayerController 播放 URL
我正在使用下面的代码在 iPhone 中播放本地电影文件 Movie.m4v
MPMoviePlayerController
并且工作正常。
现在,我已将相同的文件放入我的在线服务器 mobile.sample.com/Downloads/video/Movie.m4v
中。我想知道如何在 iPhone 中使用上述 URL 播放该电影(不使用 uiwebview
)。
我怎样才能做到这一点?寻找你的想法。感谢您的任何帮助。
- (void) readyPlayer
{
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];
}
NSLog(@"ready");
// Register to receive a notification when the movie has finished playing.
[[NSNotificationCenter defaultCenter] addObserver:self
selector:@selector(moviePlayBackDidFinish:)
name:MPMoviePlayerPlaybackDidFinishNotification
object:nil];
}
I am using the code below to play the local movie file Movie.m4v
in iPhone using theMPMoviePlayerController
and which works fine.
Now I have placed the same file into my online server mobile.sample.com/Downloads/video/Movie.m4v
. I want to know how I can play that movie using the above URL in the iPhone (not using the uiwebview
).
How can I accomplish this? Looking for your thoughts. Thanks for any help.
- (void) readyPlayer
{
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];
}
NSLog(@"ready");
// Register to receive a notification when the movie has finished playing.
[[NSNotificationCenter defaultCenter] addObserver:self
selector:@selector(moviePlayBackDidFinish:)
name:MPMoviePlayerPlaybackDidFinishNotification
object:nil];
}
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
看看无论是在线观看还是下载数据你无论如何都会消耗网络带宽。如果您不使用
UIWebView
,则可以执行以下任一操作:http 流)
您自己稍后删除它的逻辑。这样做的一大缺点是,如果
电影操作系统尺寸较大,那么您可能无法在应用程序中下载它
iOS 设备上的磁盘空间有限。
See either watch online or download the data you are anyway going to consume network bandwidth. If you are not using
UIWebView
then you can do either of the following:the http stream)
your own logic of removing it later. Big downside of this is that if
movie os of large size then you may fail to download it as you app
gets a limited disk space on iOS device.