nstudio / nativescript-audio

:microphone: NativeScript plugin to record and play audio :musical_note:
Other
149 stars 104 forks source link

Play 2 songs at the same time #155

Closed Kursorr closed 4 years ago

Kursorr commented 4 years ago

Hello everyone ! :)

I'm making a song editor with Nativescript, here is my question : How can i play 2 or 3 or ... songs at the same time ?

Thank you ! :)

Regards, Rav'

bradmartin commented 4 years ago

I don't think the native media players support two audio sources at once. So you'll need to create two instances of the audio players to do this.

Kursorr commented 4 years ago

Thank you ! :)

Works like a charm.

Here the code, that will help others too :)

    async playSongs() {
        console.log("play")
        this.player = new audio.TNSPlayer()
        const playerOptions = {
          audioFile: "~/assets/audio/rocks.mp4",
          loop: false
        }

        const secondPlayer = new audio.TNSPlayer()
        const secondPlayerOptions = {
          audioFile: "~/assets/audio/heart.mp4",
          loop: false
        }

        await this.player.playFromUrl(playerOptions)
        await secondPlayer.playFromUrl(secondPlayerOptions)
      }
Kursorr commented 4 years ago

I'm opening it again because I have a big problem. ^^

I'm making a songs editor :

image

When my timeline touch a song, that should play it for now, with what i have that play a song, but when that touch another song, that stop the first to launch the second

Here a repo : https://github.com/Ravaniss/song-editor

Someone can help with that please ? <3

ralyodio commented 1 year ago

Does it work on both android and iOS?