How to display playing indication icon on status bar? - ios

My app plays audio streams, it works fine for all cases such as background etc. I am using AudioToolbox.framework and MediaPlayer.framework to play the audio, my query is when the app starts playing audio i would want the indicator on the status bar to be shown as it does for the default iPod player.
Can anyone guide me on how to display the play indication icon on the status bar as soon as my app starts playing audio and disappears when its paused/ stopped or terminated.

As is described by iHemantk:
You just have to register for remote control events and icon will show
up:
https://developer.apple.com/library/ios/documentation/EventHandling/Conceptual/EventHandlingiPhoneOS/Remote-ControlEvents/Remote-ControlEvents.html#//apple_ref/doc/uid/TP40009541-CH7-SW3
they added this in 4.0... works well. whoever is first responder now
controls the icon... just won't work for anything pre-iOS4: put the
following in your -viewDidAppear method:
[[UIApplication sharedApplication] beginReceivingRemoteControlEvents];
[self becomeFirstResponder];
and include this method in the code:
- (BOOL) canBecomeFirstResponder {
return YES;
}
this goes in `-dealloc`:
[[UIApplication sharedApplication] endReceivingRemoteControlEvents];
and while not necessary, you may want to include this in the
-viewWillDisappear:
[self resignFirstResponder];

Related

Disable remote controls iOS

By default, remote control is activated on my streaming application but under a certain circumstance I want to disable all controllers and show nothing when the screen is locked.
First I tried to set now playing info to nil like this [[MPNowPlayingInfoCenter defaultCenter] setNowPlayingInfo: nil]; and all text, image and progress disappear but the control buttons and volume bar was still showing.
After that I tried this [[UIApplication sharedApplication] endReceivingRemoteControlEvents]; but it gives me nothing, it shows the same thing on the screen as the previous method call.
For the record, I'm calling [[UIApplication sharedApplication] beginReceivingRemoteControlEvents]; on AppDelegate before I tried to call any of the previous methods.
So, I have not found anything related to this that could help me with my problem and I would appreciate any help :)

WKWebView Media Player fullscreen detection

Before iOS 8, the UIMoviePlayerControllerDidEnterFullscreenNotification notification was sent any time a media player went to fullscreen from a UIWebView. In iOS 8, this doesn't happen and some have suggested to listen for the AVPlayerItemBecameCurrentNotification notification instead. This doesn't appear to be sent from WKWebView. Listening for the UIWindowDidBecomeVisibleNotification notification doesn't work because it's fired for all windows that are added (including things like ad networks)
Bottom line, I've been working on this all night and I can't seem to figure out how to determine if a video was opened in full screen with a WKWebView. Any help would be appreciated.
Edit: To confirm, I created a blank project. Added a UIWebView and the AVPlayerItemBecameCurrentNotification listener to it and it got triggered when I played a video and it entered full screen. I switched that UIWebView to a WKWebView and that notification was no longer triggered.
This workaround seems to work on iOS8 & iPhone 6
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {
...
[[NSNotificationCenter defaultCenter] addObserver:self selector:#selector(windowBecameHidden:) name:UIWindowDidBecomeHiddenNotification object:nil];
return TRUE;
}
- (void)windowBecameHidden:(NSNotification *)notification {
UIWindow *window = notification.object;
if (window != self.window) { // Not my own window: assuming the video window was hidden, maybe add some more checks here.
// Add code here
}
}
I just need to do the same. I listened all notifications with this answer https://stackoverflow.com/a/7955014/1271424 and found: there are no notifications about fullscreen mode at all, except notifications about creating new window (_UIWindowContentWillRotateNotification) and about MPRemote (MPRemoteCommandTargetsDidChangeNotification).
Tested on iPad, 8.1.1

Why does my app make the recording (pulsing red) status bar appear when it isn't recording?

My app sometimes uses the microphone, but even when I am not using the microphone, the red status bar appears momentarily when leaving my app.
I have set AVAudioSession's category to SoloAmbient. When I record, I set it to PlayAndRecord, and when I am done I set it back to SoloAmbient. But even when the category is SoloAmbient I still see the red status bar.
Even when my app has not accessed the microphone at all I am still getting this red status bar behavior. I do not have the app configured for background audio. Any ideas what might be making the system think that I am recording?
EDIT: After some experimentation, it looks like I can prevent the app from causing the red status bar on launch by delaying creating of the recording AUGraph until I actually start recording.
However, I still see the red status bar after stopping recording. When I stop recording, I stop the AUGraph and dispose of it and change the AVAudioSession category back to SoloAmbient. But I still see the red status bar when I switch away from the app.
After a long long long long long research and hurdles I found out simple solution for this follow as below
In Targets->General->Deployment Info check the HideStatusBar Option
like below!
And in the ViewController (Which one you kept as RootViewController) in viewDidAppear add this line of code...
[[UIApplication sharedApplication] setStatusBarHidden:NO];
Because when you uncheck HideStatusBar Option and your app needs any background process or audio related process then the status bar will become red with enlarged height. If you dont want status bar in entire app then dont add the above line in viewDidAppear and check HideStatusBar Option.

How to block iOS 7 control centre from controlling music app?

Our app explicitly blocks user form using remote-control, e.g., old springboard from pre-iOS7, earbud, by becoming the first responder to the remote-control events. However, on iOS7, the same code fails to bypass the control centre music controls.
From out tests, control centre seems to have bypassed ALL music control events including UIEventSubtypeRemoteControlPause and UIEventSubtypeRemoteControlPlay, and UIEventSubtypeRemoteControlTogglePlayPause.
Is it that control centre has its own protocol for remote control or that the way to intercept remote-control events has changed in iOS7?
The same blocking code still works perfectly with iOS6 devices. Here is what we do:
Added a method in our appDelegate:
(BOOL)canBecomeFirstResponder {
return YES;
}
Call this in applicationDidBecomeActive:
[[UIApplication sharedApplication] beginReceivingRemoteControlEvents];
// Set itself as the first responder
[self becomeFirstResponder];
Call this in applicationWillResignActive
// Turn off remote control event delivery
[[UIApplication sharedApplication] endReceivingRemoteControlEvents];
// Resign as first responder
[self resignFirstResponder];
Finally added
(void)remoteControlReceivedWithEvent:(UIEvent *)receivedEvent {
if (receivedEvent.type == UIEventTypeRemoteControl) {
switch (receivedEvent.subtype) {
case UIEventSubtypeRemoteControlTogglePlayPause:
NSLog(#"Received: UIEventSubtypeRemoteControlTogglePlayPause\n");
break;
case UIEventSubtypeRemoteControlPreviousTrack:
NSLog(#"Received: UIEventSubtypeRemoteControlPreviousTrack\n");
break;
case UIEventSubtypeRemoteControlNextTrack:
NSLog(#"Received: UIEventSubtypeRemoteControlNextTrack\n");
break;
case UIEventSubtypeRemoteControlPlay:
NSLog(#"Received: UIEventSubtypeRemoteControlPlay\n");
break;
case UIEventSubtypeRemoteControlPause:
NSLog(#"Received: UIEventSubtypeRemoteControlPause\n");
break;
case UIEventSubtypeRemoteControlStop:
NSLog(#"Received: UIEventSubtypeRemoteControlStop\n");
break;
default:
NSLog(#"Received: Some remove control events\n");
break;
}
}
}
Any pointer will be appreciated.
you can't block the music app. your app can become one though (apple won't like that) and then the control center would control yours
I think I have a better idea of what happened, at least at the CoreAudio level.
When the app's audio session category is solo-ambient, the music app's play event triggers an audio session interruption similar to an alarm clock or a phone call. This
will trigger app's audio session interruption listener callback with the "enter-interruption" state.
However, the music app's pause event does not trigger the listener callback with the "exit-interruption" state, as one would expect. This missing exit call effectively freezes our app's audio session. Quitting the control centre does not trigger it either. Same thing applies to a physical remote-control, except that the physical remote-control can be blocked using the firstResponder trick said in my last email. It does not work with Control Centre.
Unless I'm missing something obvious, I am more convinced that there are two bugs in either CoreAudio or other frameworks in the chain of command.
Bug 1: Audio session interruption listener's exit call cannot be made from music remote control if the entrance call is made first there.
Bug 2: Control Centre's music remote control does not conform to remote-control event mechanism.
I'm just surprised that no one ever reported this.
I think I'm going to file a bug report unless someone suggests differently.
UPDATE
Bug 2 was a false alarm. After clean rebuilding everything over iOS7 SDK for a couple times, we found that the problem went away. Bug 1 still holds.

AudioOutputUnitStart replace the Music app

My application (VoIP one) is using kAudioSessionCategory_PlayAndRecord category. Everything is working perfect expecting the fact that When calling AudioOutputUnitStart the Music App is replaced by my application.
Basically if I double tap the home button and flip to the music app, I can't see the default music app, instead I can see my application log near the music controls.
Anybody knows what can be?
Check if you call this somewhere
[[UIApplication sharedApplication] beginReceivingRemoteControlEvents];
[self becomeFirstResponder];
This may cause your app to appear in the music control bar

Categories

Resources