I tried to play video in a seperate UIView, so that I can leave some room for control utils such as start/stop buttons etc, so I write code like this:
First, I create an iOS project of Single View Application, then I add a View to the storyboard, at last, I append a new UIView based class named VideoView, then I associated the View to the class VideoView, and I wrote some code below:
#import "ViewController.h"
@interface ViewController ()
@end
@implementation ViewController
@synthesize moviePlayer;
- (IBAction)playMovie:(id)sender
{
VideoView *videoView = [[VideoView alloc] initWithFrame:CGRectMake(0, 0, 320, 100)];
NSString *videoPath = [[NSBundle mainBundle] pathForResource:@"Sanda" ofType:@"mp4"];
NSURL *videoURL = [NSURL fileURLWithPath:videoPath];
moviePlayer = [[MPMoviePlayerController alloc] initWithContentURL:videoURL];
//[moviePlayer.view setFrame:CGRectMake(0, 0, 320, 476)];
[moviePlayer.view setFrame:videoView.bounds];
[videoView addSubview:moviePlayer.view];
[moviePlayer prepareToPlay];
[moviePlayer play];
}
Well, I build and run it, the result is that I can just hear the sound but without seeing the video, I'm really a new comer to iOS,so any tips?
It seems that you forget to add videoView as subview. Try
[self.view addSubview: videoView];
[self.view addSubview:videoView];
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With