开发者

MPMoviePlayerController view is not adding to view controller

开发者 https://www.devze.com 2023-03-13 22:27 出处:网络
i am writing code to play video file in ownservices.m class in a method like this. -(void)playVediofile:(NSString *)vedioFileName{

i am writing code to play video file in ownservices.m class in a method like this.

-(void)playVediofile:(NSString *)vedioFileName {

NSLog(@"playing vedio file ");
NSURL *movieUrl = [NSURL fileURLWithPath:
                   [[NSBundle mainBundle] pathForResource:vedioFileName ofType:@"mp4"]];

MPMoviePlayerController* myMovie=[[MPMoviePlayerController alloc] 
                                  initWithContentURL:movieUrl];开发者_StackOverflow中文版

myMovie.scalingMode = MPMovieScalingModeNone;

myMovie.initialPlaybackTime = 2.0;

[[NSNotificationCenter defaultCenter] addObserver:self 
                                         selector:@selector(movieFinished:) 
                                             name:MPMoviePlayerPlaybackDidFinishNotification 
                                           object:myMovie]; 

[self.viewcontroller addSubview:myMovie.view];

[myMovie play];

}

i am calling this method from ownservicesviewcontroller.m class like this In a button click event.

ownServices *obj = [[ownServices alloc]init];
        [obj playVediofile:@"Movie"];

i am getting audio of the video clip,but it did n't display video.

but i am add MPMoviePlayerController view to viewcontroller.

i did n't get why it is not displaying.

why i am doing in seperate classes is because my requirement is like that,need to maintain all the methods in ownservices class and call them from ownservicesviewcontroller.m

can any one please help me.

Thank you.


You need to set the frame property of myMovie.view: e.g. you could set it to the parents bounds:

myMovie.view.frame = self.viewcontroller.bounds;

Besides this, please check your instance variable naming. It seems, that you named your view instance "viewcontroller", which just is strange. If viewcontroller is really a UIViewController type, you would need to add the myMovie.view to the viewcontroller's view property and not directly to the viewcontroller...


You need to set frame for MPMoviePlayerController's view

like: myMovie.view.frame=CGRectMake(0.0,0.0,320.0,480.0);

0

精彩评论

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