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];
Related
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 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
I am having problems setting up the YTPlayer from Youtube API programmatically and not over Storyboard as they show in their example..
This is what I have attempted to do but not luck, the video won't event load..
This is my viewDidLoad where I tried to set everything up.. Also, I almost forgot to say that I downloaded their master framework and added to my project. I changed the path as well for the .html file. I have already tried as they show with Storyboard and works but I really wanna to be able to do it programmatically.
- (void)viewDidLoad
{
[super viewDidLoad];
// Do any additional setup after loading the view, typically from a nib.
self.myView = [[YTPlayerView alloc] initWithFrame:CGRectMake(10, 80, 300, 275)];
self.myView.backgroundColor = [UIColor lightGrayColor];
[self.view addSubview:self.myView];
[self.myYoutubePlayer loadWithVideoId:#"Yf5_ZQcP7y0"];
self.playBtn = [[UIButton alloc] initWithFrame:CGRectMake(10, 400, 120, 80)];
[self.playBtn setTitle:#"Play" forState:UIControlStateNormal];
self.playBtn.backgroundColor = [UIColor redColor];
[self.playBtn addTarget:self action:#selector(playVideo:) forControlEvents:UIControlEventTouchDown];
self.stopBtn = [[UIButton alloc] initWithFrame:CGRectMake(190, 400, 120, 80)];
[self.stopBtn setTitle:#"Stop" forState:UIControlStateNormal];
self.stopBtn.backgroundColor = [UIColor redColor];
[self.stopBtn addTarget:self action:#selector(stopVideo:) forControlEvents:UIControlEventTouchDown];
[self.view addSubview:self.playBtn];
[self.view addSubview:self.stopBtn];
}
And the play and stop methods...
- (IBAction)playVideo:(id)sender {
[self.myYoutubePlayer playVideo];
}
- (IBAction)stopVideo:(id)sender {
[self.myYoutubePlayer stopVideo];
}
If more information is needed please ask first, I will be happy to provide it.. :) thanks!
The problem I had here was that the YTPlayerView framework didn't had properly define the iframe.html file to be loaded and use for the player. So, I fixed changing the TYPlayerView.m within the function -loadWithPlayerParams: and change whatever is there for the path of this file..
NSError *error = nil;
NSString *path = [[NSBundle mainBundle] pathForResource:#"YTPlayerView-iframe-player"
ofType:#"html"
inDirectory:#""];
This will make the job done..! :)
I think you have an error on your code.
You're calling "loadWithVideoId" on "self.myYoutubePlayer" and it should on "self.myView"
I'm having some issues when trying to capture more than 1 photo. The app becomes slow and then it crashes because of several memory warning. I am using Brad's GPUImage library. Here are some methods in which I use it:
//the creation of the camera view
- (IBAction)photoFromCamera
{
imageView = [[GPUImageView alloc] initWithFrame:CGRectMake(0, 0, self.view.frame.size.width, self.view.frame.size.height)];
imageView.backgroundColor = [UIColor whiteColor];
[self.view addSubview:imageView];
stillCamera = [[GPUImageStillCamera alloc] init];
stillCamera.outputImageOrientation = UIInterfaceOrientationPortrait;
//stillCamera.outputImageOrientation = UIInterfaceOrientationLandscapeLeft;
filter = [[GPUImageFilter alloc] init];
[filter prepareForImageCapture];
[stillCamera addTarget:filter];
[stillCamera addTarget:imageView];
[filter addTarget:imageView];
[stillCamera startCameraCapture];
UIButton * shotButton = [UIButton buttonWithType:UIButtonTypeRoundedRect];
shotButton.frame = CGRectMake(137, 361, 46, 30);
[shotButton setTitle:#"Take!" forState:UIControlStateNormal];
[shotButton addTarget:self action:#selector(shotAction:) forControlEvents:UIControlEventTouchUpInside];
[imageView addSubview:shotButton];
UIButton * cancelButton = [UIButton buttonWithType:UIButtonTypeRoundedRect];
cancelButton.frame = CGRectMake(10, 80, 55, 40);
[cancelButton setTitle:#"cancel" forState:UIControlStateNormal];
[cancelButton addTarget:self action:#selector(cancelAction) forControlEvents:UIControlEventTouchUpInside];
[imageView addSubview:cancelButton];
}
//The take photo action
-(void)shotAction:(UIImagePickerController *)photoPicker{
[stillCamera capturePhotoAsPNGProcessedUpToFilter:filter withCompletionHandler:^(NSData *processedPNG, NSError *error) {
self.saveButton.enabled = YES;
self.filterButton.enabled = YES;
self.cropButton.enabled = YES;
originalFirstImage = [UIImage imageWithData:processedPNG];
[self.selectedImageView setImage:originalFirstImage];
}];
[imageView removeFromSuperview];
}
is there something wrong? I'm using ARC, is there something that is not releasing?
Thanks for your comments.
EDIT: the error is: Terminated due to Memory Pressure
Shot action method have block, and block using self. Block always capture its environment, means it will reference every thing strongly. So it will cause a retain cycle, which will not allow to free memory. You should access self with weak pointer. I will suggest you that
__weak typeof(self) weakSelf = self;
and use this weakSelf in block.
EDIT
GPUImage library also have some memory leak issues reported, read this forum
I have a single button toggling between play and pause for audio playback. When I was using the standard play/pause buttons (e.g., initWithBarButtonSystemItem:UIBarButtonSystemItemPlay), I got a nice white flash animation effect over the buttons as they toggled back and forth. But now that I am using custom images, I no longer get that effect. How can I get it back?
Also would very much appreciate any tips to simplify this as it seems heavyweight. I saw https://stackoverflow.com/a/9104587/1462372 but am not clear whether that is applicable in this case (in button bar).
Here is the code:
- (void) setAsPlaying:(BOOL)isPlaying
{
self.rootViewController.playing = isPlaying;
// we need to change which of play/pause buttons are showing, if the one to
// reverse current action isn't showing
if ((isPlaying && !self.pauseButton) || (!isPlaying && !self.playButton))
{
UIBarButtonItem *buttonToRemove = nil;
UIBarButtonItem *buttonToAdd = nil;
if (isPlaying)
{
buttonToRemove = self.playButton;
self.playButton = nil;
UIImage *pauseButtonImage = [UIImage imageNamed:#"icon_pause.png"];
UIButton *pauseButton = [UIButton buttonWithType:UIButtonTypeCustom];
[pauseButton addTarget:self action:#selector(pauseAudio:) forControlEvents:UIControlEventTouchUpInside];
pauseButton.bounds = CGRectMake(0, 0, pauseButtonImage.size.width, pauseButtonImage.size.height);
[pauseButton setImage:pauseButtonImage forState:UIControlStateNormal];
self.pauseButton = [[UIBarButtonItem alloc] initWithCustomView:pauseButton];
buttonToAdd = self.pauseButton;
}
else
{
buttonToRemove = self.pauseButton;
self.pauseButton = nil;
// this was the way I was doing it before:
// self.playButton = [[UIBarButtonItem alloc] initWithBarButtonSystemItem:UIBarButtonSystemItemPlay target:self action:#selector(playAudio:)];
UIImage *playButtonImage = [UIImage imageNamed:#"icon_play.png"];
UIButton *playButton = [UIButton buttonWithType:UIButtonTypeCustom];
[playButton addTarget:self action:#selector(playAudio:) forControlEvents:UIControlEventTouchUpInside];
playButton.bounds = CGRectMake(0, 0, playButtonImage.size.width, playButtonImage.size.height);
[playButton setImage:playButtonImage forState:UIControlStateNormal];
self.playButton = [[UIBarButtonItem alloc] initWithCustomView:playButton];
buttonToAdd = self.playButton;
}
// Get the reference to the current toolbar buttons
NSMutableArray *toolbarButtons = [[self.toolbar items] mutableCopy];
// Remove a button from the toolbar and add the other one
if (buttonToRemove)
[toolbarButtons removeObject:buttonToRemove];
if (![toolbarButtons containsObject:buttonToAdd])
[toolbarButtons insertObject:buttonToAdd atIndex:5];
[self.toolbar setItems:toolbarButtons];
}
}
Try this code might be helpful to you...
UIImage* image = [UIImage imageNamed:#"facebook.png"];
CGRect frame = CGRectMake(0, 0, image.size.width, image.size.height-10);
UIButton *rightbtnItem = [[UIButton alloc] initWithFrame:frame];
[rightbtnItem setBackgroundImage:image forState:UIControlStateNormal];
[rightbtnItem setShowsTouchWhenHighlighted:YES];
Copy and paste it in your viewDidload and see glow effect on touch.
UIButton *button=[UIButton buttonWithType:UIButtonTypeCustom];
[button setImage:[UIImage imageNamed:#"ar.png"] forState:UIControlStateNormal];
[button setFrame:CGRectMake(0, 0, 30, 30)];
button.center=self.view.center;
[button setBackgroundImage:[UIImage imageNamed:#"RS2kQ.png"] forState:UIControlStateHighlighted];
Get Image from here ar.png and RS2kQ.png