I want to add action on the all button who shows bellow picture . I add this view through .. following code --
AVPlayerViewController *playerViewController = [[AVPlayerViewController alloc] init];
playerViewController.view.frame = CGRectMake(10,10, _bgView.frame.size.width-20, _bgView.frame.size.height-20);
playerViewController.player = [AVPlayer playerWithURL:url1];
[_bgView addSubview:playerViewController.view];
_bgView.autoresizesSubviews = TRUE;
So please help me for add the action on this buttons
Yes..... I resolve that issues... the right code is--
_playerViewController = [[AVPlayerViewController alloc] init];
_playerViewController.view.frame=CGRectMake(10,10, _bgView.frame.size.width-20, _bgView.frame.size.height-20);
_playerViewController.player = [AVPlayer playerWithURL:url1];
Related
In my app we are using AVPlayer to play a audio file. In iOS 11 Beta versions the audio is playing fine but the player is not visible. its just displaying a black background.
can any one help me to solve this issue?
_avpvc = [[AVPlayerViewController alloc] init];
AVPlayerItem *aPlayerItem = [[AVPlayerItem alloc] initWithURL:url];
_avpvc.player = [[AVPlayer alloc] initWithPlayerItem:aPlayerItem];
_avpvc.player = [AVPlayer playerWithURL:url];
[self.view addSubview:self.avpvc.view];
self.avpvc.view.frame = self.audioPlayerView.bounds;
self.avpvc.view.autoresizingMask =
UIViewAutoresizingFlexibleHeight | UIViewAutoresizingFlexibleWidth;
[self.audioPlayerView addSubview:self.avpvc.view];
[self.avpvc didMoveToParentViewController:self];
[_avpvc.player play];
You need to create your own custom player to serve the purpose.Using UISliders and UIbuttons.By Default you won't get Player UI.
I am trying to play mp3 and other audio formats stored on a server with AVPlayer, but every time I get error EXC_BAD_ACCESS.
However, I am able to play these audio files on the browser on chrome.
My Code is in viewDidLoad like this
AVPlayerViewController *playerController = [AVPlayerViewController new];
AVPlayer *songPlayer = [[AVPlayer alloc] initWithURL:[NSURL URLWithString:#"http://mplayer.example.com/Recordings/sun.mp3"]];
playerController.player = songPlayer;
playerController.view.frame = self.view.frame;
[playerController.view sizeToFit];
playerController.videoGravity = AVLayerVideoGravityResizeAspect;
playerController.showsPlaybackControls = YES;
[songPlayer play];
[self.view insertSubview:playerController.view atIndex:0];
I can't figure out what's wrong with my code because my URL is correct and I can fetch audio files from this URL.
You provided URL showing me this message "This webpage is not available
ERR_NAME_NOT_RESOLVED". I tested your code with this URL "http://clips.vorwaerts-gmbh.de/big_buck_bunny.mp4". It is working fine.
I have a UIViewController subclass called videoPlayerViewController.
In storyboard I dragged out a UIViewController. I set the class correctly in Storyboard.
I put a button on the screen. When I click the button, it executes the method playVideo:.
- (IBAction)playVideo:(id)sender
{
NSURL *movieURL = [NSURL URLWithString:#"http://www.ebookfrenzy.com/ios_book/movie/movie.mov"];
MPMoviePlayerController *player =
[[MPMoviePlayerController alloc] initWithContentURL: movieURL];
[player prepareToPlay];
[player.view setFrame: self.view.bounds]; // player's frame must match parent's
[self.view addSubview: player.view];
[player play];
}
I get a black screen that does nothing.
This is the simplest version of the code I've had in this method over the last 6 hours.
I've tried every StackOverflow answer out there.
I just want to play a video that I stream from the internet.
If I set:
player.movieSourceType = MPMovieSourceTypeStreaming;
the screen reads "loading" for a second, and then crashes.
What exactly am I doing wrong?
I understand there are so many MPMoviePlayerController questions out there, and to just ask a general "How does it work" question seems ludicrous. I've been at this almost 6 hours now and no Google/Stack Overflow/Apple Documentation search has made this work.
I used your provided code but created a MoviePlayerController property named mcp in the header file that I assigned to player to after creating it. That worked for me. The movie loaded and played just fine.
In the .h file:
#property (strong, nonatomic) MPMoviePlayerController *mcp;
In the .m file:
- (IBAction)playVideo:(id)sender
{
NSURL *movieURL = [NSURL URLWithString:#"http://www.ebookfrenzy.com/ios_book/movie/movie.mov"];
MPMoviePlayerController *player = [[MPMoviePlayerController alloc] initWithContentURL: movieURL];
[player prepareToPlay];
[player.view setFrame: self.view.bounds]; // player's frame must match parent's
_mcp = player;
[self.view addSubview: _mcp.view];
[_mcp play];
}
Using the code at the bottom of this post I can successfully display a movie. However I need to now use moviePlayer as a property rather than a local variable. So by adding the following in the header file:
#property (retain, nonatomic) MPMoviePlayerController *mPlayer;
...and synthesizing it as:
#synthesize mPlayer = _mPlayer
Here's the original code. This works fine. All I change is the initialisation line where instead of using a local variable I use the property. A
MPMoviePlayerController * mPlayer = [[[MPMoviePlayerController alloc] initWithContentURL:videoURL] autorelease];
mPlayer.shouldAutoplay=YES;
[self.welcomeImage setUserInteractionEnabled:YES];
[mPlayer.view setFrame: self.welcomeImage.bounds]; // player's frame must match parent's
[self.welcomeImage addSubview:mPlayer.view];
mPlayer.scalingMode = MPMovieScalingModeAspectFit;
mPlayer.controlStyle = MPMovieControlStyleEmbedded;
[mPlayer prepareToPlay];
[mPlayer play];
I just get a black box, no controls or video. What am I doing wrong?
Your not using your synthesized property. Change mPlayer to _mPlayer.
_mPlayer = [[[MPMoviePlayerController alloc] initWithContentURL:videoURL] autorelease];
_mPlayer.shouldAutoplay=YES;
[self.welcomeImage setUserInteractionEnabled:YES];
[_mPlayer.view setFrame: self.welcomeImage.bounds]; // player's frame must match parent's
[self.welcomeImage addSubview:_mPlayer.view];
_mPlayer.scalingMode = MPMovieScalingModeAspectFit;
_mPlayer.controlStyle = MPMovieControlStyleEmbedded;
[_mPlayer prepareToPlay];
[mPlayer play];
This should work as long your videoURL is valid.
I tried running my working 3.1.x application on 3.2 and realized that
the MPPlayerController framework had changed.
After doing some research the common method should be to add the
MPMoviePlayerViewController's view as a subview.
Somehow this does not work for me ...
I have TTTableViewController with items such as :
[TTTableSubtitleItem itemWithText:#"Text" subtitle:#"subtitle" imageURL:#"bundle://1.jpg" defaultImage:nil URL:#"tt://videos/0" accessoryURL:nil],
This is then mapped:
[map from:#"tt://videos/(playMovieAtIndex:)" toViewController: [VideoViewController class]];
and the VideoViewController finally plays the movie:
MPMoviePlayerViewController* controller =
[[MPMoviePlayerViewController alloc] initWithContentURL:theURL];
if (controller)
{
self.mp = controller;
self.mp.moviePlayer.controlStyle = MPMovieControlStyleFullscreen;
self.mp.moviePlayer.scalingMode = MPMovieScalingModeAspectFit;
self.mp.moviePlayer.movieSourceType = MPMovieSourceTypeFile;
[controller release];
[self presentMoviePlayerViewControllerAnimated:self.mp];
[self.mp.moviePlayer play];
}
But only audio is played, and the MoviePlayer view is not actually
shown.
What am I doing wrong ?
I had the same problem. My quick work-around was to not use:
[self presentMoviePlayerViewControllerAnimated:self.mp];
But instead, add the subview to the parent controller manually:
[self.view addSubview:self.mp.view];