开发者

How to add the play, stop... button to a video

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:MPMoviePlayerPl开发者_StackOverflow社区aybackDidFinishNotification 
                                               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


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


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


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

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜