iOS Question How to play next song in background

Discussion in 'iOS Questions' started by tuhatinhvn, Feb 4, 2015.

  1. tuhatinhvn

    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: Feb 4, 2015
  2. Erel

    Erel Administrator Staff Member Licensed User

    Have you tried to start the next song when the Complete event fires?
     
  3. Turbo3

    Turbo3 Active Member Licensed User

    Seems like the Complete event only fires in the foreground.
     
  4. Erel

    Erel Administrator Staff Member Licensed User

  5. tuhatinhvn

    tuhatinhvn Active Member Licensed User

    Yes i worked, i can play in backgroud

    But i want to next song when the song finish, but complete events not work when app in backgroud

     
  6. Erel

    Erel Administrator Staff Member Licensed User

    Try this, add these two lines to Application_Start:
    Code:
    Dim no As NativeObject = app
     no.RunMethod(
    "beginReceivingRemoteControlEvents"Null)
     
  7. tuhatinhvn

    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
    Code:
    - (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
     
  8. Erel

    Erel Administrator Staff Member Licensed User

    Try to add this code with #If OBJC and see whether the event is raised.
     
  9. tuhatinhvn

    tuhatinhvn Active Member Licensed User

    how to use #if OBJC with this void ??
    Code:
    - (void)remoteControlReceivedWithEvent:(UIEvent *)receivedEvent {
    and call it

    Code:
    NativeMe.RunMethod("remoteControlReceivedWithEvent"Null)
    ???
    I tested but it has errors
     
  10. Erel

    Erel Administrator Staff Member Licensed User

    Try this code (untested):
    Code:
    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
     
  11. tuhatinhvn

    tuhatinhvn Active Member Licensed User

    does not work....

    Can you test it? and give us an example about it???
     
  12. Pendrush

    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 likes this.
  13. tuhatinhvn

    tuhatinhvn Active Member Licensed User

    Me too, @Erel
    Please check it for us, since from begin day of B4i i need this function with play audio online
     
  14. Erel

    Erel Administrator Staff Member Licensed User

    You should start a new thread in the wishlist forum for this.
     
Loading...
  1. This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
    By continuing to use this site, you are consenting to our use of cookies.
    Dismiss Notice