I'm using https://github.com/youtube/youtube-ios-player-helper for implement Youtube videos in my iOS Project.
I implement the YTPlayerView object in Appdelegate; in my ViewController I execute the view. Really YTPlayerView, is a UIView that show an UIWebview.
The proble occure when I want to listen the webview (Youtube Music) in background.
- (void)applicationDidEnterBackground:(UIApplication *)application{
[self.playerView playVideo];
}
I implement this in Appdelegate but the first time I dismiss the app, the music is set in background, but the second time no and I don't know why.
I have seen so many apps at app store that u can make this, so is possible but I don't have seen anything about it.
Thanks
Related
here is my problem:
I've got an app playing audio files, updating the lockscreen info via MPNowPlayingInfoCenter.defaultCenter().nowPlayingInfo, and this part is working fine.
But in an other view, i'm playing a video with AVPlayerViewController and AVPlayer, and when the video starts playing, it's updating the lock screen automatically, with nothing except the video duration.
I didn't find anything about this behaviour in Apple's documentation, I can't find a way to disable it.
So far, I've tried calling UIApplication.sharedApplication().endReceivingRemoteControlEvents() before the video starts playing, and beginReceivingRemoteControlEvents() after. It doesn't work.
Does anyone know a way to prevent this?
Starting with iOS 10 there is a BOOL property in AVPlayerViewController called updatesNowPlayingInfoCenter, that has the default value: YES. Just change it to NO:
//playerController is an instance of AVPlayerViewController
if ([self.playerController respondsToSelector:#selector(setUpdatesNowPlayingInfoCenter:)])
{
self.playerController.updatesNowPlayingInfoCenter = NO;
}
I am using UIWebView in an iOS app to play YouTube videos but to provide native experience, I've implemented playback controls using UIKit. So the UIWebView is only used to display video.
I've also implemented -remoteControlReceivedWithEvent: to allow control from Control Center and controller buttons on earphones. But it seems that UIWebView automatically handles remote control events from the earphones. This is a problem because when you toggle play/pause, my code would pause the video and then UIWebView will toggle it again to play the video.
Is there anyway to prevent this from happening?
Related issue is that UIWebView tries to set "Now Playing" information to MPNowPlayingInfoCenter which is also done by my code.
I encountered same kind of issue with my app which playbacks audio using AVAudioPlayer.
This app displays current audio info in MPNowPlayingInfoCenter during playback.
My requirement was to display an html5 video advert (with audio) inside a webview on top my player.
First i used only UIWebView as i needed to support iOS7 but i met a lot of issues, one of them was MPNowPlayingInfoCenter that displays url of ad video in place of current native audio playback.
I tried several solutions such as method swizzling on UIWebView without any success.
I found only one solution that works for me: use WKWebView by default instead of UIWebView web container. HTML5 video playback will not interact anymore with MPNowPlayingInfoCenter, i had to support also iOS7 so i created a wrapper class to switch between UIWebView (with still the issue) on iOS7 and WKWebView from iOS8 and more.
Hope this helps.
I ran into this question while trying to solve somewhat the reverse problem: I added a UIWebView to an app and remote control events were not working when the UIWeb view was on display, but worked elsewhere in the app.
In my case the solution was to add these 3 methods, which are present on all other view controllers in my app, to the controller of my new UIWebView:
- (void) viewDidAppear:(BOOL)animated {
[self becomeFirstResponder];
}
- (void)viewWillDisappear:(BOOL)animated {
[super viewWillDisappear:animated];
[self resignFirstResponder];
}
-(void)remoteControlReceivedWithEvent:(UIEvent *)event {
// Logic to handle remote control events
}
From this, I suspect that you can prevent your UIWebView from handling remote control events by doing one of two things:
1. Include logic in the remoteControlReceivedWithEvent to ignore the remote control events you don't want handled.
2. Have your UIWebView resign being the first responder by calling resignFirstResponder in the viewDidAppear method of the controller.
I am developing an app with a background music and the music starts when the first view (INTROViewController) appears (it is implemented in viewDidLoad). I have created a settings page (OPTIONSViewController) where I have implemented a switch to turn the music on and off. In OPTIONSViewController I have created an instance of INTROViewController where all the audio files and the commands to play and stop the music are defined. I don't get any errors but it seems the instance is not able to control the music at all, which continues playing. What am i doing wrong? Cheers
I think u can have just one AVPlayer on your AppDelegate.
Declare it like a property, and then u can get this player from all your application
with something like this:
yourAppDelegate* appDele= (yourAppDelegate*)[[UIApplication sharedApplication]delegate];
AVPlayer * tempPlayer = [appDele yourPlayer];
This should fix your problem :D
I'm working on a project that plays YouTube videos, inline in a UIWebView. What I'm trying to do is to continue playing the app's audio, even when the home button is pressed (or focus is off the app in any way). I've done the following (as suggested from searching my question here):
Made sure Audio and Fetch were included in my info.plist for Background Modes
Made sure my ViewController that contained the WebView is registered to receive remote control events:
[[UIApplication sharedApplication] beginReceivingRemoteControlEvents];
[self becomeFirstResponder];
Messed with the AVAudioSession (sharedSession) and set the category to playback.
None of these things worked. Either I'm doing one of them incorrectly (which I doubt--I've found several "solutions" here that have worked for other people but not for my particular case).
I have a feeling this might have something to do with the way the WebView plays audio. Any ideas?
You need to add BackgroundMode: "Audio And AirPlay".
It's the following key in your plist:
`<key>UIBackgroundModes</key>
<array>
<string>audio</string>`
I'm trying to track video and audio plays as screen views using the GA iOS SDK v2. Is this possible?
Normally one would replace the uiviewcontroller reference with GItrackedviewcontroller. This doesn't seem to be an option.
Yes, this is possible. You can manually invoke
[tracker sendView:#"My view name"];
everytime you open a video or audio stream.
The GAITrackedViewController does nothing other than placing exactly this sendView call in the viewDidAppear (or viewWillAppear, not sure about that).