如何向视频添加播放、停止...按钮
我使用此代码在我的应用程序中显示视频,
NSURL *movieUrl = [NSURL fileURLWithPath:
[[NSBundle mainBundle] pathForResource:@"myvideoname"
ofType:@"mp4"]];
//create a new instance of MPMoviePlayerController
MPMoviePlayerController* myMovie=[[MPMoviePlayerController alloc]
initWithContentURL:movieUrl];
//disable scaling of our movie
myMovie.scalingMode = MPMovieScalingModeNone;
[myMovie.view setFrame: myView.bounds]; // player's frame must match parent's
[myView addSubview: myMovie.view];
[[myMovie view] setFrame:[myView bounds]];
//don't show any controls
// myMovie.movieControlMode = MPMovieControlModeHidden;
//you can specify at which time the movie should
//start playing (default is 0.0)
myMovie.initialPlaybackTime = 2.0;
//register a callback method which will be called
//after the movie finished
[[NSNotificationCenter defaultCenter] addObserver:self
selector:@selector(movieFinished:)
name:MPMoviePlayerPlaybackDidFinishNotification
object:myMovie];
myMovie.scalingMode = MPMovieScalingModeAspectFill;
//start the movie (asynchronous method)
[myMovie play];
// Do any additional setup after loading the view from its nib.
它工作正常,但我想添加控件(播放、停止、声音控制...) 我该怎么办?谢谢
i use this code to display a video in my app
NSURL *movieUrl = [NSURL fileURLWithPath:
[[NSBundle mainBundle] pathForResource:@"myvideoname"
ofType:@"mp4"]];
//create a new instance of MPMoviePlayerController
MPMoviePlayerController* myMovie=[[MPMoviePlayerController alloc]
initWithContentURL:movieUrl];
//disable scaling of our movie
myMovie.scalingMode = MPMovieScalingModeNone;
[myMovie.view setFrame: myView.bounds]; // player's frame must match parent's
[myView addSubview: myMovie.view];
[[myMovie view] setFrame:[myView bounds]];
//don't show any controls
// myMovie.movieControlMode = MPMovieControlModeHidden;
//you can specify at which time the movie should
//start playing (default is 0.0)
myMovie.initialPlaybackTime = 2.0;
//register a callback method which will be called
//after the movie finished
[[NSNotificationCenter defaultCenter] addObserver:self
selector:@selector(movieFinished:)
name:MPMoviePlayerPlaybackDidFinishNotification
object:myMovie];
myMovie.scalingMode = MPMovieScalingModeAspectFill;
//start the movie (asynchronous method)
[myMovie play];
// Do any additional setup after loading the view from its nib.
it work fine but i want to add the controls ( play , stop , sound control ...)
How can i do ? thanx
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
使用什么 controlStyle?
MP电影控制风格
描述播放控件样式的常量。
What using controlStyle?
MPMovieControlStyle
Constants describing the style of the playback controls.
您应该设置控件样式 ,例如
myMovie.controlStyle = MPMovieControlStyleDefault;
添加控制栏。You should set the control style, like
myMovie.controlStyle = MPMovieControlStyleDefault;
to add a control bar.在
MPMoviePlayerController
对象上定义controlStyle
属性。描述播放控件样式的常量。
从 此处
Define the
controlStyle
property on theMPMoviePlayerController
object.Constants describing the style of the playback controls.
Read more from here