iOS Question How to play next song in background

tuhatinhvn

Active Member
Licensed User
THank Erel for guide to play audio in background with video view

I can play music in background now (when press home music continue play)

But i see many apps play music can play next song when the last song finish in background (not in app), can i do it with B4I with VIdeo View ? THank you
 
Last edited:

tuhatinhvn

Active Member
Licensed User
Thank @Erel , it work, but i can understand, this command is use for press play/pause, next or previos in lockscreen or when swipe from bottom of iphone.

But only
no.RunMethod("beginReceivingRemoteControlEvents", Null) command, this function not work (when i press to pause or play button in lockscreen or when swipe from bottom of iphone nothing happen)
I read Iphone SDK documents, they say about this:

https://developer.apple.com/library...emote-ControlEvents/Remote-ControlEvents.html
B4X:
- (void)remoteControlReceivedWithEvent:(UIEvent *)receivedEvent {
    if (receivedEvent.type == UIEventTypeRemoteControl) {
        switch (receivedEvent.subtype) {
            case UIEventSubtypeRemoteControlTogglePlayPause:
                [self playOrStop: nil];
                break;
            case UIEventSubtypeRemoteControlPreviousTrack:
                [self previousTrack: nil];
                break;
            case UIEventSubtypeRemoteControlNextTrack:
                [self nextTrack: nil];
                break;
            default:
                break;
        }
    }
}
How can i convert or use it in B4I? Thank for @Erel help this topic about background media play very much, i think other members will learn many many thing from this topic, thank you
 

tuhatinhvn

Active Member
Licensed User
Try to add this code with #If OBJC and see whether the event is raised.
how to use #if OBJC with this void ??
B4X:
- (void)remoteControlReceivedWithEvent:(UIEvent *)receivedEvent {
and call it

B4X:
  NativeMe.RunMethod("remoteControlReceivedWithEvent", Null)
???
I tested but it has errors
 

Erel

Administrator
Staff member
Licensed User
Try this code (untested):
B4X:
Private Sub RemoteControl_Event(Subtype As Int)
   Log("Subtype: " & Subtype)
End Sub

#If OBJC
- (void)remoteControlReceivedWithEvent:(UIEvent *)receivedEvent {
  if (receivedEvent.type == UIEventTypeRemoteControl) {
     [self.bi raiseEvent:nil event:@"remotecontrol_event:"
       params:@[@(receivedEvent.subtype)]];
   }
}
#end if
You can see the constants values here: https://developer.apple.com/library...tion/UIKit/Reference/UIEvent_Class/index.html
 

Pendrush

Well-Known Member
Licensed User
I have try Erel's code and I can't make event RemoteControl_Event to fire. App work, but nothing happened when i click on pause, play, next, previous on lock screen.
 

tuhatinhvn

Active Member
Licensed User
I have try Erel's code and I can't make event RemoteControl_Event to fire. App work, but nothing happened when i click on pause, play, next, previous on lock screen.
Me too, @Erel
Please check it for us, since from begin day of B4i i need this function with play audio online
 
Top