I am trying to create a player like in a image below, starting from play and pause button. but it's not showing up on a player. how can i create customize panel for my player, custom bar, volume bar etc?
- (IBAction)playMovie:(UIButton *)sender {
NSURL *url = [[NSURL alloc] initWithString:urlStr.text];
self.movie = [[MPMoviePlayerController alloc]initWithContentURL:url];
self.movie.controlStyle = MPMovieControlStyleNone;
self.movie.shouldAutoplay = YES;
[self.view addSubview:self.movie.view];
[self.movie setFullscreen:YES animated:YES];
playButton = [[UIButton alloc] initWithFrame:CGRectMake(100, 200, 100, 100)];
[playButton setImage:[UIImage imageNamed:#"apple.png"] forState:UIControlStateNormal];
[playButton addTarget:self action:#selector(playButtonPressed:) forControlEvents:UIControlEventTouchUpInside];
[self.view addSubview:playButton];
}
add player on a view with button like your image describes
moviePlayerController = [[MPMoviePlayerController alloc] initWithContentURL:urlVideo];
[moviePlayerController.view setFrame:CGRectMake(0, 170, 320, 270)];
[self.view addSubview:moviePlayerController.view];
moviePlayerController.fullscreen = YES;
[moviePlayerController play];// put it in action
Related
- (void)playMethod
{
NSURL *url = [[NSURL alloc] initWithString:#"https://www.rmp-
streaming.com/media///bbb-360p.mp4"];
player = [AVPlayer playerWithURL:url];
controller = [[AVPlayerViewController alloc] init];
[self addChildViewController:controller];
[self.view addSubview:controller.view];
controller.view.frame = CGRectMake(15,50,345,300);
controller.player = player;
controller.showsPlaybackControls = YES;
player.closedCaptionDisplayEnabled = NO;
UIButton *button1 = [UIButton buttonWithType:UIButtonTypeCustom];
[button1 addTarget:self
action:#selector(backMethod)
forControlEvents:UIControlEventTouchUpInside];
[button1 setTitle:#"Back" forState:UIControlStateNormal];
[button1 setTitleColor:[UIColor whiteColor] forState:UIControlStateNormal];
button1.frame = CGRectMake(50.0, CGRectGetMinY(controller.view.frame)+10, 160.0, 40.0);
button1.tag = 1001;
[self.view addSubview:button1];
[controller.view bringSubviewToFront:button1];
[player pause];
[player play];
}
I want to play the video in landscape mode currently, its getting played in portrait mode. I want when the playMethod is called it should open the video in landscape mode only.
Create your custom class which is inherited from AVPlayerViewController and use this instead of base AVPlayerViewController
import AVKit
class CustomAVPlayerViewController: AVPlayerViewController {
override var supportedInterfaceOrientations: UIInterfaceOrientationMask {
return .landscapeLeft
}
}
I cannot work this out - it should be simple.
I have:
ShowAVPlayer method
AVPlayerItem *video = [[AVPlayerItem alloc] initWithURL:url];
AVQueuePlayer *queue = [[AVQueuePlayer alloc] initWithItems:#[video]];
video = [[AVPlayerItem alloc] initWithURL:url];
[queue insertItem:video afterItem:nil];
AVPlayer *player = [AVPlayer playerWithURL:url];
self.avmovieplayer = [AVPlayerViewController new];
I want to add a button to my overlay - but the button is not responding :
UIButton *btn = [UIButton buttonWithType:UIButtonTypeRoundedRect];
[btn setTitle:#"Do stuff" forState:UIControlStateNormal];
btn.frame = CGRectMake(0, 330, 320, 40);
[btn addTarget:self action:#selector(DoSpeech:) forControlEvents:UIControlEventTouchUpInside];
[btn setUserInteractionEnabled:true];
[self.avmovieplayer.contentOverlayView addSubview:btn];
Here is my DoSpeech which is never being called:
- (void) DoSpeech:(UIButton *)button {
//DoSpeech
}
Try this,
[btn setUserInteractionEnabled:YES];
[self.avmovieplayer.contentOverlayView bringSubviewToFront:btn];
Hope it will help.
I'm using AVPlayerViewController and can't showing the Done button, and can't close the player also. maybe you can help me. This is my code in objective-c
UIView *view = self.view;
NSURL *fileURL = [NSURL URLWithString: _detailData[0]];
AVPlayerViewController *playerViewController = [[AVPlayerViewController alloc] init];
playerViewController.player = [AVPlayer playerWithURL:fileURL];
self.avPlayerViewcontroller = playerViewController;
[self resizePlayerToViewSize];
[self dismissViewControllerAnimated:YES completion:nil];
[view addSubview:playerViewController.view];
[playerViewController.player play];
view.autoresizesSubviews = TRUE;
Need help guys, thank you very much.
UIButton *button = [UIButton buttonWithType:UIButtonTypeCustom];
[button addTarget:self
action:#selector(aMethod:)
forControlEvents:UIControlEventTouchUpInside];
[button setTitle:#"Done" forState:UIControlStateNormal];
button.frame = CGRectMake(80.0, 210.0, 160.0, 40.0); // set your own position
[view addSubview:button]; // or you can add [playerViewController.view addSubview:button];
-(void)aMethod:(UIButton *)button {
// Remove playerViewController.view
}
thanks for your answer. I found it already :)
We can using this, and done button can shown automatically.
NSURL *fileURL = [NSURL URLWithString: _detailData[0]];
// create an AVPlayer
AVPlayer *player = [AVPlayer playerWithURL:fileURL];
// create a player view controller
AVPlayerViewController *controller = [[AVPlayerViewController alloc]init];
controller.player = player;
[player play];
// show the view controller
[self addChildViewController:controller];
[self.view addSubview:controller.view];
controller.view.frame = self.view.frame;
I have a storyboard. In my viewDidLoad I can show and play my movie, but any buttons on the storyboard are hidden. I can add them in code, but would prefer my graphic elements to be laid out on my storyboard and have them sit on top of the movie. Suggestions most appreciated. Code here:
- (void)viewDidLoad
{
[super viewDidLoad];
// Do any additional setup after loading the view.
NSString *videoPath = [[NSBundle mainBundle] pathForResource:#"foo" ofType:#"mov"];
NSURL *url = [NSURL fileURLWithPath:videoPath];
moviePlayer = [[MPMoviePlayerController alloc] initWithContentURL:url];
[[NSNotificationCenter defaultCenter] addObserver:self
selector:#selector(moviePlayBackDidFinish:)
name:MPMoviePlayerPlaybackDidFinishNotification
object:moviePlayer];
if ([UIDevice currentDevice].userInterfaceIdiom == UIUserInterfaceIdiomPad) {
moviePlayer.view.frame = CGRectMake(0.0f,0.0f,1024.0f,768.0f);
}
moviePlayer.controlStyle = MPMovieControlStyleNone;
[moviePlayer prepareToPlay];
moviePlayer.repeatMode = MPMovieRepeatModeOne;
moviePlayer.shouldAutoplay = YES;
[self.view addSubview:moviePlayer.view];
[moviePlayer setFullscreen:YES animated:YES];
[self.moviePlayer play];
// manually can add buttons here, but prefer not too it in code
UIButton *myButton = [UIButton buttonWithType:UIButtonTypeRoundedRect];
[myButton addTarget:self
action:#selector(aMethod:)
forControlEvents:UIControlEventTouchDown];
myButton.frame = CGRectMake(26.0, 585.0, 474.0, 87.0);
myButton.titleLabel.shadowOffset = CGSizeMake(0.0, 0.0);
[myButton.titleLabel setFont:[UIFont systemFontOfSize:35]];
}
Solved. Created new layer. Simple.
i am creating one iPad application in that i want to open media player to play video. For this i create one button in ViewDidLoad() method. Bellow is my code.
- (void)viewDidLoad
{
[super viewDidLoad]
self.view.backgroundColor = [[[UIColor alloc] initWithPatternImage:[UIImage imageNamed:#"1.png"]] autorelease];
m_btn2000 = [[UIButton buttonWithType:UIButtonTypeCustom] autorelease];
m_btn2000.frame = CGRectMake(180, 330, 130, 200);
[m_btn2000 setImage:[UIImage imageNamed:#"2.png"] forState:UIControlStateNormal];
m_btn2000.clipsToBounds = YES;
[m_btn2000 addTarget:self action:#selector(btnClicked:) forControlEvents:UIControlEventTouchUpInside];
[self.view addSubview:m_btn2000];
}
Bellow is my button clicked method code:
- (void)btnClicked:(id)sender
{
NSString *filePath1 = [[NSBundle mainBundle] pathForResource:#"test_video" ofType:#"m4v"];
NSURL *fileURL = [NSURL fileURLWithPath:filePath1];
m_moviePlayer = [[MPMoviePlayerController alloc] initWithContentURL:fileURL];
m_moviePlayer.controlStyle = MPMovieControlStyleFullscreen;
[m_moviePlayer.view setFrame:CGRectMake(0, 0, 1026, 748)];
[self.view addSubview:m_moviePlayer.view];
[m_moviePlayer play];
}
when i m going to click on button it gives me EXC_BAD_ACCESS error.
But i notice one thing that when i put above whole code which in button clicked method putting in ViewDidLoad() method it play a video in player proper way.
The reason is : you are creating a button with + (factory method) and you are sending autorelease message.
you need to change this line from:
m_btn2000 = [[UIButton buttonWithType:UIButtonTypeCustom] autorelease];
to
m_btn2000 = [UIButton buttonWithType:UIButtonTypeCustom];