remove info and control in Control Center from UIWebView - ios

if we place the url which contains video in a UIWebView, and play with it.
the control center will have the info and controls of the video.
is there a way to remove this info and control ?
I found this question asking is that UIWebView player a MPMoviePlayerController instance, and how to get a reference to that instance?
although the answer been accepted, but it doesn't reveal the real player in UIWebView, if I knew what it is, maybe I could find more info about how it works, and how to deal with it.
since I'm the one put the UIWebView in the app, I should have the control, right?
I try to get the AVPlayer with url by this question Get current track playing on control center iOS, but it's returning a new AVPlayer, so is AVQueuePlayer and AVPlayerLayer.. no matter what I did to them, there won't be any effect in the control center..
I found this piece in WWDC sessions
it looks convincing, will this be the right direction ?

I was introduced to method swizzling by #DaidoujiChen
it helps me filter the event of registering remove control from UIWebView
find out which method you don't wanna be touched by others
perform the method by the flag you defined, that's all !
- (void)avoidWebViewUse_beginReceivingRemoteControlEvents {
if ([ JukeboxMacro sharedSingleton ].requestingRemoteControl) {
[ self avoidWebViewUse_beginReceivingRemoteControlEvents ];
} else {
NSLog(#"UIWebView trying to beginReceivingRemoteControlEvents ");
}}

Related

iOS - Reset the command center / remote player

I'm using different kinds of players in my app. I have some kind of control over all of them, but one of them I don't, at all.
When I play an embedded video from a UIWebView, specifically.
My issue is, the app requires audio to be played in background, which works fine. Note, the video's audio does not need to be played in background. But that means I need to use the remote controls (command center & lock screen commands).
My issue is the following :
After I've played a video from an embed, the remote controls still control that video, even though it's been dismissed. And when I press "play", it plays both my radio AND the embedded video.
How can I "clear the memory" of the command center ?
I have enough information to know when to apply a solution, I don't know what the solution is though.
Solution can include a complete disability to use the command center while playing the embed video, or until my radio is played. Solution can include some kind of "hard reset" of the command center.
Actually, any solution is welcome.
This question is a little bit old, but I just fixed this issue and feel like this could help someone out. The thing that was preventing me from reseting the command center was that I had added target actions that were persisting past the instance of my view controller's lifecycle.
Here's what my code looked like.
On the view controller:
var commandPlay: Any?
var commandPause: Any?
When adding the targets:
commandPlay = commandCenter.playCommand.addTarget {event in
self.startButtonTapped(self.startButton)
MPNowPlayingInfoCenter.default().nowPlayingInfo?[MPNowPlayingInfoPropertyPlaybackRate] = 1.0
return .success
}
commandPause = commandCenter.pauseCommand.addTarget {event in
self.startButtonTapped(self.startButton)
MPNowPlayingInfoCenter.default().nowPlayingInfo?[MPNowPlayingInfoPropertyPlaybackRate] = 0.0
return .success
}
At dismiss to remove the targets (important part):
commandCenter.playCommand.removeTarget(commandPlay)
commandCenter.pauseCommand.removeTarget(commandPause)

Disabling autoplay in FB video ads getting called on but still auto playing - objective C

I have just embedded video ads from facebook and i can't get them to stop autoPlaying.
According to the documentation there is a property to disable AutoPlay, which i added, it's getting called on but not working.
(https://developers.facebook.com/docs/reference/ios/current/class/FBMediaView/)
I tried setting it to no in right after initializing the view and also tried right after adding it as a subview.
In both cases when i put a break point i see that the value of the property changes to NO, but by the time the ad itself actually show it autoplays again!
Anyone had the pleasure of working with this?
This is how i tried:
(void)nativeAdDidLoad:(FBNativeAd *)nativeAd {
adCoverMediaView = [[FBMediaView alloc] initWithNativeAd:nativeAd];
[adCoverMediaView setNativeAd:nativeAd];
[adCoverMediaView setAutoplayEnabled:NO];
//after this didn't work i tried adding it here: (later in the same method)
[legacyAdView addSubview:adCoverMediaView];
[adCoverMediaView setAutoplayEnabled:NO];

Player Modal transition like the one in Spotify

I'm building a music app and I would like to make a transition like the one Spotify (and other music apps like the new Apple Music) does to present its player, a minimized player which expands an covers the main view (modally?) by dragging it or tapping it.
How can I achieve this? Is there any API or idea on how to do this?
You might want to look at open-source LNPopupController. It provides similar presentation behaviour much like the Music app.
I found a couple of cocoacontrols that might be helpful:
The first One and I think the most accurate KNSemiModalViewController, this one used in the National Geographic app its more or less what you need, you would only need to present a full screen view and remove the background animation if you want.
MWWindow Another possible solution.
MJPopupViewController
Now all of this controls dont have the "minimize" function just like spotify, the only one I found with this function is SLParallaxController, but you need to figure out how to change the map and the tableview for the content that you want, or just see how he does the dismiss/minimize animation.

How to prevent Nuance's DragonMobile from turning off VoiceOver?

Nuance's DragonMobile component apparently turns off VoiceOver announcements between the initial call to SKRecognizer's initWithType:detection:language:delegate and the component's call to recognizerDidFinishRecording:. It makes some sense that they do this, since they don't want the VoiceOver announcements to be picked up by the mic and transcribed.
The problem is that there's usually a 1-2 second gap between the initialization of the recognizer and the initial call to recognizerDidBeginRecording:. In order to prevent the user's first few words from getting cut out of the transcription, it's necessary to use recognizerDidBeginRecording: to indicate to the user that they should start speaking (i.e. you can't just have them hit the mic button and start speaking immediately).
My problem is that since DragonMobile turns off VoiceOver as soon as initWithType: is called, I have no way of indicating to a VoiceOver user that they should begin talking at the appropriate time.
Found something of a workaround: DragonMobile allows you to specify SKEarcons, which are audio files that play whenever recording is started, stopped or canceled. I'm going to record VoiceOver making the announcements that I need and then use these recordings as the earcons, so that it will sound like the rest of VoiceOver.
According to a Nuance technical rep I just spoke to, DragonMobile does indeed take over the audio layer and suppress any output during recording, and they don't expose any way around this other than the earcons.

Can I support VoiceOver in my Cocos2D-iPhone Game?

I'm making a game where a player reacts to sounds via motion - seeing as the visual element isn't needed to play it, and many play with their eyes closed, it seems a shame to not be fully VoiceOver compatible. I'm currently using Cocos2D-iPhone and CocosDenshion for audio, and am now starting to think about how I'll be building my menu system to choose levels and configure controls.
Is it reasonably easy to support VoiceOver in Cocos2D's menu system, or should I look in to trying to create my menus in UIKit which I have no experience using?
I don't know if Cocos' menu system supports VoiceOver, but if it doesn't, you could probably add the functionality you're looking for yourself without having to delve into a lot of UIKit work. All you need to do is create a UIView subclass which gets added to your main window when your app starts up. Then use the UIAccessibilityContainer protocol and UIAccessibilityPostNotification calls to allow users to interact with your game via VoiceOver.
The UIAccessibilityContainer protocol lets you inform VoiceOver what interface elements are currently on the screen, their labels, their traits, etc. VoiceOver then uses this information to let users swipe between elements and get feedback on them.
When your game changes state, you can change what that protocol sends back and then issue a
UIAccessibilityPostNotification(UIAccessibilityLayoutChangedNotification, nil)
...to inform VoiceOver that the screen layout has changed. And to just speak something via VoiceOver, say when your game state has changed, you can send a different notification to speak some text:
UIAccessibilityPostNotification(UIAccessibilityAnnouncementNotification, #"Achievement unlocked!");
No need to go with UIKit framework you can go with the cocos2d native methods and class to implement this.
For sound option we have SimpleAudioEngine Which can be used. you can distinguish between sound using its ID which is of type ALuint.
ALuint soundEffectID;
//to start
soundEffectID=[[SimpleAudioEngine sharedEngine] playEffect:#"my sound"];
//to stop
[[SimpleAudioEngine sharedEngine] stopEffect:soundEffectID];
You have to mange these effect and I think your problem will be solved.

Resources