So, I've tried this a number of ways with the same result.
I've tested by using a YouTube MP4 URL, such as:
This
The way I do it looks pretty much like:
self.moviePlayer = [[MPMoviePlayerViewController alloc] initWithContentURL:[NSURL URLWithString:videoUrlString]];
And then I play the video. If I play the video and it goes fullscreen, the whole app locks up. The video player appears, but parts of the status bar (such as the time and bars) disappear leaving only the carrier name. The volume slider is only half there, and it loads indefinitely, and ignores any further touch input until I kill the app. If I rotate the iPhone, the volume slider and the rest of the status bar reappear, but it still will not respond to touch or finish loading. Screenshot of issue.
If, instead, I pass the MPMoviePlayerViewController object to a UINavigationController with presentViewController:, the app seems to hang: until I rotate, then suddenly the video appears correctly and starts playing! However, again, all touch input is ignored and the application is essentially locked.
This is one of the strangest issues I've troubleshot.
So I tried using tools others have built. I tried XCDYouTubeKit and YKMediaKit using the Youtube ID instead of the direct link, with the exact same result. After looking at their code, they both use MPMoviePlayerViewControllers.
What's happening here? Can anyone help me figure out what's wrong?
That's surprising. Have you tried playing around with AV Foundation? It's a more modern media API than MediaPlayer.framework.
If you can target iOS 8 only, then AVPlayerViewController is a simple way to playback media via AVPlayer.
Related
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).
I have followed the many helpful previous questions to get my AVPlayer successfully streaming video when my app goes to the background. There are two methods described on Apple's QA1668 and they both work for my stream urls.
The problem is that there is a noticeable audio gap during the transition that is identical for both methods. On my iPhone 6 in release mode I would say the gap is less than 0.5 seconds, which may not seem terrible but if I'm playing something like a music video this is very distracting.
After more testing it looks like this gap actually occurs when I remove the AVPlayerLayer (or, if I am using the other method, when I disable the AVMediaCharacteristicVisual tracks) as I have determined it will still happen if I hook those actions up to a button rather than the backgrounding state.
My guess is that is has something to do with the audio re-syncing to the new video state of the AVPlayer but really I have no clue. Any help would be greatly appreciated!
I have an app that is streaming Video data using an AVPlayer. The AVPlayer is using a APLEAGLView to render the pixels to the screen.
The issue I'm having is that I have a textbox within the same view. If you tap on the textbox and enter text with the keyboard it works fine.
However, if I use Siri's voice to text function on the textbox, then try play the video again, the audio plays and currentTime changes but the video is frozen on the frame that was there when you began the voice to text function.
This was fine previously but since a recent Apple update this is now broken.
Any help would be greatly appreciated as one of our biggest client's is complaining about this.
So I could not find the exact cause of the issue, but I did manage to fix it.
The issue was that the previous developers used an OPEN GL ES View to render the pixel buffer to the screen. I refactored it to use the standard AVPlayerLayer functionality and that fixed the issue.
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!
I have a MPMoviePlayer whose controls have been hidden.
I have custom sliders to move the video, back and forth and controls to control the speed as well.
Now whenever it reaches the end I can see a white screen.
app does not crash but I can't see the video.
I tried debugging and realized that moviPlayer instance is still there, but naturalSize is reported to be zero.
rest everything is there, including the contentURL property.
has the player released the video ?
UPDATE:
The bug onbly appears on iOS4 and not on iOS5.
Anyone any idea on what changes have come to movieplayer in the two versions which we might have missed.