2011-05-22 62 views
1

我用这个代码在我的应用程序如何按钮来添加播放,停止...到视频

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. 

它做工精细显示视频,但我想添加控件(播放,停止,声音控制...) 我该怎么办? thanx

回答

0

什么使用controlStyle

myMovie.constrolStyle = MPMovieControlStyleEmbedded; 

MPMovieControlStyle 常量描述的播放控制的样式。

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

常量

MPMovieControlStyleNone显示 没有控制。可在
iOS 3.2及更高版本中使用。声明于
MPMoviePlayerController.h。

MPMovieControlStyleEmbedded
显示嵌入视图的控件。
该控制包括一个开始/暂停
按钮,进度条,并用于全屏和
嵌入式显示模式之间切换的按钮
。可在
iOS 3.2及更高版本中使用。声明于
MPMoviePlayerController.h。

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

MPMovieControlStyleDefault
全屏控件默认显示。
Available in iOS 3.2及更高。
在MPMoviePlayerController.h中声明。
MPMovieFinishReason

0

应设置control style,像myMovie.controlStyle = MPMovieControlStyleDefault;增加一个控制条。

+0

@Henrik @ texmex5谢谢你的回答。我添加了myMovie.controlStyle = MPMovieControlStyleEmbedded;坚果没有改变。我havint明白我在哪里把枚举:(我把它放在.h,.mi总是有错误... – user761812 2011-05-22 22:44:18

+0

你不必添加枚举到你的头文件。只有你需要添加的行是myMovie .controlStyle = MPMovieControlStyleEmbeded。 – texmex5 2011-05-23 06:22:56

0

定义MPMoviePlayerController对象上的controlStyle属性。

描述播放控件风格的常量。

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

了解更多从here

相关问题