如何向视频添加播放、停止...按钮

发布于 2024-11-09 04:54:36 字数 1540 浏览 0 评论 0原文

我使用此代码在我的应用程序中显示视频,

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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

掌心的温暖 2024-11-16 04:54:36

使用什么 controlStyle?

myMovie.constrolStyle = MPMovieControlStyleEmbedded;

MP电影控制风格
描述播放控件样式的常量。

enum {
   MPMovieControlStyleNone,
   MPMovieControlStyleEmbedded,
   MPMovieControlStyleFullscreen,
   MPMovieControlStyleDefault = MPMovieControlStyleFullscreen
};
typedef NSInteger MPMovieControlStyle;

常量

MPMovieControlStyleNone
不显示任何控件。可用于
iOS 3.2 及更高版本。声明于
MPMoviePlayerController.h。

MPMovieControlStyleEmbedded
显示嵌入视图的控件。
控件包括开始/暂停
按钮、滑动条和按钮
用于在全屏和
之间切换
嵌入式显示模式。可用于
iOS 3.2 及更高版本。声明于
MPMoviePlayerController.h。

MPMovieControlStyle全屏
显示全屏播放控件。
控件包括开始/暂停
按钮、滑动条、前进和
反向搜索按钮,用于
的按钮
在全屏和
之间切换
嵌入式显示模式,一个按钮
切换纵横比填充模式,以及
完成按钮。点击完成按钮
暂停视频并退出全屏
模式。适用于 iOS 3.2 及更高版本。
在 MPMoviePlayerController.h 中声明。

MPMovieControlStyleDefault
默认情况下显示全屏控件。
适用于 iOS 3.2 及更高版本。
在 MPMoviePlayerController.h 中声明。
MPMovieFinishReason

What using controlStyle?

myMovie.constrolStyle = MPMovieControlStyleEmbedded;

MPMovieControlStyle
Constants describing the style of the playback controls.

enum {
   MPMovieControlStyleNone,
   MPMovieControlStyleEmbedded,
   MPMovieControlStyleFullscreen,
   MPMovieControlStyleDefault = MPMovieControlStyleFullscreen
};
typedef NSInteger MPMovieControlStyle;

Constants

MPMovieControlStyleNone
No controls are displayed. Available in
iOS 3.2 and later. Declared in
MPMoviePlayerController.h.

MPMovieControlStyleEmbedded
Controls for an embedded view are displayed.
The controls include a start/pause
button, a scrubber bar, and a button
for toggling between fullscreen and
embedded display modes. Available in
iOS 3.2 and later. Declared in
MPMoviePlayerController.h.

MPMovieControlStyleFullscreen
Controls for fullscreen playback are displayed.
The controls include a start/pause
button, a scrubber bar, forward and
reverse seeking buttons, a button for
toggling between fullscreen and
embedded display modes, a button for
toggling the aspect fill mode, and a
Done button. Tapping the done button
pauses the video and exits fullscreen
mode. Available in iOS 3.2 and later.
Declared in MPMoviePlayerController.h.

MPMovieControlStyleDefault
Fullscreen controls are displayed by default.
Available in iOS 3.2 and later.
Declared in MPMoviePlayerController.h.
MPMovieFinishReason

酒与心事 2024-11-16 04:54:36

您应该设置控件样式 ,例如 myMovie.controlStyle = MPMovieControlStyleDefault; 添加控制栏。

You should set the control style, like myMovie.controlStyle = MPMovieControlStyleDefault; to add a control bar.

雪化雨蝶 2024-11-16 04:54:36

MPMoviePlayerController 对象上定义 controlStyle 属性。

描述播放控件样式的常量。

enum {
   MPMovieControlStyleNone,
   MPMovieControlStyleEmbedded,
   MPMovieControlStyleFullscreen,
   MPMovieControlStyleDefault = MPMovieControlStyleFullscreen
};
typedef NSInteger MPMovieControlStyle;

此处

Define the controlStyle property on the MPMoviePlayerController object.

Constants describing the style of the playback controls.

enum {
   MPMovieControlStyleNone,
   MPMovieControlStyleEmbedded,
   MPMovieControlStyleFullscreen,
   MPMovieControlStyleDefault = MPMovieControlStyleFullscreen
};
typedef NSInteger MPMovieControlStyle;

Read more from here

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文