iOS Question Player error on iOS 13

Pendrush

Well-Known Member
Licensed User
Longtime User
This code
B4X:
- (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)];
}
called with
B4X:
NativeMe.RunMethod("register", Null) ' this is line 727 from error log below

give this error in iOS 13 simulator:

Any solution for this?
 

Erel

B4X founder
Staff member
Licensed User
Longtime User
Update the inline code to:
B4X:
#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];
    success = [audioSession setPreferredSampleRate:4096 error:nil];
    [[UIApplication sharedApplication] beginReceivingRemoteControlEvents];
  }
  if (!success) {
    [NSException raise:@"" format:@"Error setting audio session: %@", err];
    NSLog(@"Error setting category Audio Session: %@", [err localizedDescription]);
  }
}
- (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)];
}
- (MPMediaItemArtwork*)createArtwork:(UIImage*) image {
   return [[MPMediaItemArtwork alloc] initWithBoundsSize:image.size requestHandler:^UIImage* _Nonnull(CGSize aSize) { return image; }];
}
- (MPRemoteCommandHandlerStatus ) play {
   [self.bi raiseEvent:nil event:@"controlevent:"  params:@[@"play"]];
   return MPRemoteCommandHandlerStatusSuccess;
   
}
- (MPRemoteCommandHandlerStatus ) pause {
   [self.bi raiseEvent:nil event:@"controlevent:"  params:@[@"pause"]];
   return MPRemoteCommandHandlerStatusSuccess;
   
}
#End If
 
Upvote 0
Cookies are required to use this site. You must accept them to continue using the site. Learn more…