Clearing after-image from Airplay device, using UIWebView - ios

I send a secondary UI to AirPlay - on iOS 5.1.
On the iPad, the user may use a UIWebView to play a video, and if they have Airplay setup, the video will be sent to the AirPlay device. When the video finishes playing or if the user pauses, the UIWebView does not clear out the image from the AirPlay screen.
If I then load a different URL to the UIWebView, the AirPlay image will clear out, but only after a few seconds.
I've tried to work-around this by loading a blank page, and then reloading the original video page, but that does not seem to work. Any thoughts?

In my effort to also clear other types of content from a UIWebView, I happened to discover that the following statement will also disconnect the AirPlay video connection immediately, and thereby revealing any underlying secondary UI sent via UIScreen.
[myWebView stringByEvaluatingJavaScriptFromString:#"document.body.innerHTML = \"\";"];

Related

Using the 'YouTube-Player-iOS-Helper', is it possible to not pause playback when removing the YTPlayerView from the screen?

I am developing a music app that plays audio, regular video (such as mp4) and youtube videos. It has the proper background mode enabled, as the app plays audio and regular video correctly in the background.
The following issue appears only on the iPad, not on the iPhone.
Using the YouTube-Player-iOS-Helper on iOS 8, adding the youtube video content (YTPlayerView) to another view (as a subview) works great, even when playing. However, removing that YTPlayerView from its superview automatically pauses the playback, which isn't always the desired case (sending the app to the background causes the same effect).
Is it possible to change that behaviour?
I can rationalize manually resuming the playback when the app goes to the background, however, doing the same for the 'remove from superview scenario' causes the playback to stutter for a moment.
The issue can easily be reproduced with the sample app for 'YouTube-Player-iOS-Helper', by playing a video and then changing between tabs. On the iPhone, the player does NOT pause, but on the iPad, the player DOES pause.
If it's impossible, is there other Youtube SDKs that allow this behaviour and still adhere to the official terms and conditions?
Thanks
Figured this one.
The YTPlayerView will NOT pause, on iPad or iPhone, if you remove it from its superview and immediately add it to a view again (can be a different view). That view must be inside a view controller properly rooted in the view hierarchy (not detached).

Prevent AirPlay from sleeping

I have an app that uses AirPlay. I am using the iPad to present data on a TV. The user sets up the demo and then puts the device down and the app should take care of updating the TV even in the background state. The app is processing data in the background and I can see it is always being updated. However the AirPlay disconnects after a few minutes if nothing on the screen changes.
How can I prevent AirPlay from disconnecting?
Note:
I am not streaming video or audio. I am only presenting data using views.
Update:
After more twiddling I found that the background task dies after 10 minutes and that is when the screen dies. I tried to play a sound like https://stackoverflow.com/a/15732710/1449607 described but the AirPlay still disconnected. I am now toggling a pixel and now it seems that the screen is staying connect. There must be a better solution for displaying slowly updating data to AirPlay.

AVComposition breaks on Airplay

I have a video composition which I'd like to play over Airplay (without mirroring). The app works as expected when using normal Airplay mirroring, but I'd like to get the speed, reliability, and resolution bump you get from using Airplay video instead.
The problem is that when I set
player.usesAirPlayVideoWhileAirPlayScreenIsActive = YES;
...the player goes blank.
Notes:
Since I don't create separate windows for each display, they are both trying to use the same AVPlayer.
My AVVideoComposition contains different files and adds opacity ramps between them.
This unanswered question suggests that the problem is more likely due to the fact that I'm playing an AVComposition than the use of a shared player: AVComposition doesn't play via Airplay Video
Two questions:
Do I have to get rid of the player on the iPad?
Can an AVVideoComposition ever be played over AirPlay?
I can't make comments so I had to post this as an answer although it might not fully respond to the questions.
I had similar issue and at the end I found out that when AVPlayer plays AVComposition it simply doesn't display anything on the external display. That's why I had to do it myself by listening to UIScreen connection notifications.
I have to say that all worked pretty perfect. I'm checking first if there are more than one screen and if there are I simply move the AVPlayer on that screen while displaying a simple message on the device's screen that content is played on... plus the name of AirPlay device. This way I can put whatever I want on the external display and is not very complicated. Same thing is when I receive UIScreenDidConnectNotification.
That was fine until I noticed that the composition plays really choppy on the the external display. Even if it consists of only one video without any complex edits or overlays. Same video plays perfectly if I save it to the Camera Roll or if I use MPMoviePlayerController.
I've tried many things like lowering resolutions, lowering renderScale and so on but with no success.
One thing bothers me more is how actually Apple do this in iMovie - if you have AirPlay enabled and you play a project (note it's still not rendered so it must use a composition in order to display it) right after tapping play button it opens a player that plays content really smoothly on the external monitor. If you however activate AirPlay from the player it closes and start rendering the project. After that it plays it I thing by using MPMoviePlayerController.
I'm still trying to find a solution and will post back if I have any success.
So for the two questions:
I don't see why you have to get rid.
Yes it can be played but with different technique and obviously issues.
in the app .plist create a new item called:
required background modes
add a new array element called:
App plays audio or streams audio/video using AirPlay
Not sure if you have already tried this, but you don't mention it in your post.
Cheers!

Purpose of mediaPlaybackAllowsAirPlay property on UIWebView

The UIWebView Class Reference describes mediaPlaybackAllowsAirPlay as follows:
A Boolean value that determines whether Air Play is allowed from this view.
When the mediaPlaybackAllowsAirPlay is set to YES:
If on my iPad I load a YouTube or Vimeo video to a UIWebView with this set to it's default value of YES and play the video while mirroring to an AirPlay device, the video signal is sent to the AirPlay device and takes over the AirPlay device screen and "TV Connected / This video is playing on the TV" is displayed in the UIWebView on the AirPlay. This is the behavior I would expect.
When the mediaPlaybackAllowsAirPlay is set to NO:
I get exactly the same behavior as above. What I expected is that if the UIWebView mediaPlaybackAllowsAirPlay was set to NO, that instead of sending the video signal to the AirPlay device, even if the iPad is mirroring, the video would simply play inside the UIWebView on the iPad.
Has anyone used this property to create two different functional behaviors and what were they?
As far as I can tell, this property has no impact on the playing of AirPlay media.
It appears that the mirroring mode is taking precedence over the mediaPlaybackAllowsAirPlay flag.
If I'm interpreting the documentation correctly, mediaPlaybackAllowsAirPlay only allows the user to send the data to a particular airplay compatible device. If it is disabled, the airplay selector simply doesn't show up.
If this is a bug to you, please head over to http://bugreporter.apple.com and let Apple know.

iOS: background play from the browser?

Some iOS apps like Pandora continue playing audio after the app screen has been exited, and even after the device has been locked.
Is it possible to keep audio playing in this way from a browser tab? In other words, can I code an HTML5 page that plays audio and continues playing even after the iPhone is locked?
Yes, audio playing in a mobile Safari tab will continuously play even when multi-tasking or locking your screen. However, if you save the bookmark to the home screen, open, play audio, and then hop out to multi-task, the audio fades out.
Not possible... the browser displaying your page controls what happens when it is deactivated (sent to the background). HTML5 won't touch the behavior of the underlying browser as it relates to system events, so the only way to control background activity in iOS is to write a native app.

Resources