Nativescript-audio implementation


#1

Hello !

I do not know how to release this.

I have a playlist and an instance of nativescript-audio, the first audio that is selected have normal play, but when I select another until the first song is not ending, I have a this.player.dispose() and then I made the this.player.play with the next song selected. The problem is when I have changed around three times the song, the app get crashed.

All this audios are mp3 from url.

Can anyone give a suggest for this? Am I doing right?


#2

If you’re using the @bradwaynemartin plugin, the d.ts file indicates that this.player.dispose returns a promise. Meaning that calling the dispose function does not implies that you can still play another song. You have to ensure that you received the callback before playing another one.

You could use it this way in your component :

    public playNextSong() {
      if(this.isPlayerAvailable) {
         this.isPlayerAvailable = false;
         this.player.start(xxx);

      } else {
        this.player.dispose().then(() => { this.isPlayerAvailable=true; this.playNextSong() });
      }
    }

In other words, you should always wait for the player to stop before starting another one.


#3

Trying to recall from memory, I think dispose() should kill the player instance. You should only use it when you’re done playing audio. It’s for freeing up native resources/memory on the device. Just FYI :smile: - might add a note on the README about this.

iOS - might have an issue where it’s not disposing of the instance. So it’s possible we have some inconsistencies there. I think I have an issue to circle back and fix that on the audio plugin.


#4

yes, I need to work with you on this audio plugin. In my app, PracticeBuddy, students record their sessions and they are uploaded to Firebase, then the teachers can listen to them ad hoc. I have a teacher who reports consistent crashing when trying to listen to a file downloaded via Firebase. I’d love to work w/ u to debug. Can’t leave the kids hanging!! :slight_smile:


#5

Definitely. Next week I can free some time to give this plugin some love :heart: and with @wwwalkerrun iOS help maybe squash any bugs you have for iOS specifically. I’m assuming that’s the crashing platform :thinking: we need to fix the dispose() method on iOS to actually remove the player instance so it’s consistent with Android so iOS users aren’t creating new instances of audio players on iOS.

Just looked and you are using dispose() https://github.com/jlooper/practicebuddy/blob/master/app/teacher-student-home/teacher-student-home.component.ts#L88 - I haven’t looked any more yet but only call this if you are done playing audio. It should destroy the audio player (iOS is inconsistent right now and will get fixed soon) so if you dispose the player you will need to create a new instance. This also might be the cause of the iOS crashes that occur for some and not all users. I think @wwwalkerrun knows dispose should not be used unless done so he never sees the crash and I guess we need to make it more clear on the README that dispose should kill the player instance. So maybe all the segfaults reported are really just player instances being used incorrectly by the api design we have and again why nathan never sees it himself - at least hoping that is it :thinking: :smile: will make fixing easier.


#6

@Eric @bradwaynemartin @jen.looper thanks a lot ! my app still crashing but I still trying :smiley:


#7

iOS is a bit funny I might have a few things to share what I did when I’m navigating away from the page/route that uses the player that’s the only time I dispose of the player also in the play from file you can set it to init only so you can have some extra control on how things play and instead of calling all those dispose functions get the native instance and use that to skip the track you see each time you make the call to dispose then create a new instance the garbage man probably hasn’t clean up the old things left in the memory


#8

please share! we want teh codez !