Until now I can press a button and start playing music and go to background and continue playing.
When the app is in foreground I receive a silent push notification and start playing a music and if the app goes to background continue playing
When the app in in background I receive the silent push notification but the music doesn´t start
Someone can help ?
definition
code
When the app is in foreground I receive a silent push notification and start playing a music and if the app goes to background continue playing
When the app in in background I receive the silent push notification but the music doesn´t start
Someone can help ?
definition
B4X:
#PlistExtra: <key>UIBackgroundModes</key>
#PlistExtra: <array>
#PlistExtra: <string>audio</string>
#PlistExtra: <string>remote-notification</string>
#PlistExtra: </array>
code
B4X:
Private Sub Application_RemoteNotification (Message As Map, CompletionHandler As CompletionHandler)
Dim xTitulo, xMsg As String
xTitulo = Message.Get("title")
xMsg = Message.Get("message")
Log($"Message arrived: ${Message}"$)
NativeMe.RunMethod("setAudioSession", Null)
MyPlayer1.Initialize(File.DirAssets, "manera.mp3","MyPlayEnd")
MyPlayer1.Looping=False
MyPlayer1.Play
' Msgbox(xMsg, xTitulo )
ch = CompletionHandler
' CompletionHandler.Complete
End Sub
#If OBJC
@import MediaPlayer;
#import <AVFoundation/AVFoundation.h>
#import <AudioToolbox/AudioToolbox.h>
- (void)setAudioSession {
AVAudioSession *audioSession = [AVAudioSession sharedInstance];
NSError *err = nil;
BOOL success = [audioSession setCategory:AVAudioSessionCategoryPlayback error:&err];
if (success) {
success = [audioSession setActive:YES error:&err];
}
if (!success)
[NSException raise:@"" format:@"Error setting audio session: %@", err];
}
- (void)register {
MPRemoteCommandCenter* center = [MPRemoteCommandCenter sharedCommandCenter];
center.playCommand.enabled = true;
center.pauseCommand.enabled = true;
[center.playCommand addTarget:self action:@selector(play)];
[center.pauseCommand addTarget:self action:@selector(pause)];
}
- (void) play {
NSLog(@"test");
[self.bi raiseEvent:nil event:@"controlevent:" params:@[@"play"]];
}
- (void) pause {
[self.bi raiseEvent:nil event:@"controlevent:" params:@[@"pause"]];
}
#end if