How to show Airplay button in MPMoviePlayerController iOS 8 - ios

I have an app in which I am playing a video using MPMoviePlayerController with custom controls. I'm adding a feature so that users can mirror the play back in Apple TV for this i have implemented the following code.
MPVolumeView *volumeButton = [[MPVolumeView alloc] initWithFrame:CGRectMake(80.0, 210.0, 160.0, 40.0)];
volumeButton.showsVolumeSlider = NO;
volumeButton.showsRouteButton = YES;
[self.view addSubview:volumeButton];
But Airplay button is not visible in iOS 8. Is there any way to show Airplay button in MPMoviePlayerController?
Please provide your suggestions and valuable inputs.

Related

AirPlay doesn't appear in iOS 10

SOLVED
With iOS 10.2 AirPlay button has reappeared and it still works. Apple poltergeist!
In iOS 9 I used this code to detect Airplay devices. With deployment target 10.00 it doesn't appear. In Control Center I can find my airplay devices, but in my app the uiview doesn't show anything.
In my capabilities I have checked under "background mode", Audio, AirPlay and picture in picture. Maybe I forget some new setting of this blessed sandbox?
Thanks for your patience
#property (weak, nonatomic) IBOutlet UIView *airplay;
MPVolumeView *myVolumeView = [[MPVolumeView alloc] initWithFrame: airplay.bounds];
[myVolumeView setShowsVolumeSlider:NO];
[myVolumeView setShowsRouteButton:YES];
myVolumeView.transform = CGAffineTransformMakeScale(0.3,0.3);
[myVolumeView setRouteButtonImage:[UIImage imageNamed:#"myIconAirPlay"] forState:UIControlStateNormal];
[airplay addSubview: myVolumeView];
From apple doc :
If there is an Apple TV or other AirPlay-enabled device in range, the route button allows the user to choose it. If there is only one audio output route available, the route button is not displayed.
https://developer.apple.com/reference/mediaplayer/mpvolumeview
Have you checked if var areWirelessRoutesAvailable: Bool { get } returns true or false on the MPVolumeView ?
I thinks it's the reason why your button is no longer appearing, It wouldn't be new if iOS10 update broke some Airplay devices until they have been updated too.

Play audio in background (play when using other APP)

I created an app for streaming audio (and send mail as well) but I have a problem, my app will not keep playing after I press the home button.
I use XCODE 6.4 and the mediaplayer.framework to play the stream it is in viewcontroller and I have been activating the background mode Audio & airplay.
Can someone please let me know what I am doing wrong here, I really want to learn it.
code:
NSURL *videoStreamURL = [NSURL URLWithString:#"http://streamlink.m3u"];
_player = [[MPMoviePlayerController alloc] initWithContentURL:videoStreamURL];
_player.view.frame = CGRectMake(0, 530, self.view.frame.size.width, 38);
[self.view addSubview:_player.view];
[_player play];

Play video in app instead of default player

I use the following code to play videos:
MPMoviePlayerViewController *theMovie=
[[MPMoviePlayerViewController alloc] initWithContentURL: movieURL];
theMovie.moviePlayer.repeatMode=MPMovieRepeatModeOne;
[self presentMoviePlayerViewControllerAnimated:theMovie];
This causes a the default movie player to cover the app. Instead I want the video to play inside the app itself as follows:
Can this be achieved?
You can set its frame like this:
theMovie.view.frame = CGRectMake(10, 10, 300, 300);
Then without presenting it add it as subview:
[self.view addSubview: theMovie.view];
Hope this helps.. :)
Yes, this can be achieved by using the AVPlayerLayer. Please see examples here:
"AV Foundation Programming Guide", "Putting It All Together: Playing a Video File Using AVPlayerLayer" section
A tutorial from the iosguy.com
Appuccino's "Playing Movies With AVPlayerLayer In iOS 6" video tutporial

Audio Route Button - AirPlay

I am currently playing audio through AudioQueues. I would like to allow users to connect to Airplay devices.
If I create an MPVolumeView and use the 'showsRouteButton' to display the route button I can successfully connect.
Is there a way to change the Audio Route to Airplay without using the MPVolumeView? Or a simpler Apple view that is just the route button?
1 hide MPVolumeView and make it as global var
CGRect frame = CGRectZero;
frame.origin.y = 0;
frame.origin.x = 410; // out of the screen
_volumeView = [[MPVolumeView alloc] initWithFrame:frame];
[_volumeView setShowsVolumeSlider:NO];
[_volumeView setShowsRouteButton:YES];
[self.view addSubview:_volumeView];
2 simulate button tapes
- (IBAction)handleAirPlay:(id)sender {
for (UIButton *button in _volumeView.subviews)
{
if ([button isKindOfClass:[UIButton class]])
{
[button sendActionsForControlEvents:UIControlEventTouchUpInside];
}
}
}
I don't think there is any other way to show the airplay route button (at least in current SDK iOS 5.1).. If you want to show AirPlay options you have to use MPVolumeView..
Since iOS 11 you can use AVRoutePicker :
import AVKit
let rpv = AVRoutePickerView()
view.addSubview(rpv)

MPMoviePlayerController stops and resets the movie when user tries to play fullscreen [iOS]

I embedded a MPMoviePlayerController on my mail view. I can play/pause the movie and seek forward/backward. But when I touch the "fullscreen button" the movie stops and the playback state is set to MPMoviePlaybackStateStopped... Should the movie be played in full screen?
Here is my code:
MPMoviePlayerController *player = [[MPMoviePlayerController alloc] initWithContentURL:videoUrl];
player.shouldAutoplay = NO;
player.movieSourceType = MPMovieSourceTypeFile;
player.controlStyle = MPMovieControlStyleEmbedded;
player.allowsAirPlay = YES;
player.view.frame = CGRectMake(xPos, yPos, width, height);
[self.view addSubview:player.view];
I found my bug: when pressing the full screen toggle button in MPMoviePlayerController's view, the method "viewWillLayoutSubviews" is invoked. I could never imagine this behavior...
I hope my experience can be useful to other developers.
Remember that any containing ViewController will have its viewWillDisappear, viewDidDisappear methods invoked when the MPMoviePlayerController goes full screen. Also, viewWillAppear and viewWillDisappear get called when it comes back from full screen.
If you have any logic in there that affects video playback behavior, it'll get called unless you use some conditional logic to see if the video is still playing.

Resources