iOS Question How to make Mediaplayer ignore the silence ringer switch setting?

Turbo3

Active Member
Licensed User
Longtime User
How can we make Mediaplayer ignore the phone ringer silence switch setting?

I did find that if I added the code to allow mediaplayer to play in the background and when the phone is off it also seems to have made it ignore the silence ringer switch setting.
 

Erel

B4X founder
Staff member
Licensed User
Longtime User
It is a similar solution. You need to add this objective c code and call it before you initialize media player.

B4X:
Sub Process_Globals
   Public App As Application
   Public NavControl As NavigationController
   Private Page1 As Page
   Private mp As MediaPlayer
End Sub

Private Sub Application_Start (Nav As NavigationController)
   NavControl = Nav
   Dim jo As NativeObject = Me
   jo.RunMethod("setAudioSession", Null)
   Page1.Initialize("Page1")
   NavControl.ShowPage(Page1)
   mp.Initialize(File.DirAssets, "01.mp3", "mp")
   mp.Play
End Sub


#If OBJC
#import <AVFoundation/AVFoundation.h>
- (void) setAudioSession {
AVAudioSession *audioSession = [AVAudioSession sharedInstance];
BOOL ok;
NSError *setCategoryError = nil;
ok = [audioSession setCategory:AVAudioSessionCategoryPlayback
  error:&setCategoryError];
if (!ok) {
  NSLog(@"%s setCategoryError=%@", __PRETTY_FUNCTION__, setCategoryError);
}
}
#end if
 
Upvote 0
Top