facebook

Playing Multiple Audio

💡
Our Forums Have Moved

For help with installation, bugs reports or feature requests, please head over to our new forums.
Genuitec Community on GitHub

  1. MobiOne Archive
  2.  > 
  3. Getting Help – General
Viewing 4 posts - 1 through 4 (of 4 total)
  • Author
    Posts
  • #333803 Reply

    tony
    Member

    Hi, i used custom_audio_demo help file to play a single file assigned to a button. but is it possible to play multiple audio assigned to a button. i attached my design files…

    Attachments:
    You must be logged in to view attached files.
    #333827

    Hi Tony,

    >but is it possible to play multiple audio assigned to a button.
    Yes, it is very doable. One approach is to use javascript to create the logic to identify what mp3 file is playing and stop it and then start playback the other one. Do you have javascript programming skills?

    #333854

    tony
    Member

    i got two buttons and i am using the code below but i’m not sure how to make changes,

    /**
    * Called when document is loaded.
    */
    phoneui.documentReadyHandler = function() {
    initAudio();
    initAudio1();
    }
    //create a hidden <audio> element to play the src mp3 file;
    //configure button click handler to toggle play on/off
    function initAudio() {
    audio = new Audio();
    audio.src = ‘1.mp3’;

    isPlaying = false;

    buttonId = ‘#m1-custom-audio-demo2-playstop-btn’;
    $(buttonId).click(toggleAudio);

    //stop audio when changing browser page or click home btn
    $(window).bind(‘pagehide’,stopAudio);
    }

    function toggleAudio() {
    if (isPlaying) {
    stopAudio();
    } else {
    playAudio();
    }
    }

    //start playing, update button label to STOP
    function playAudio() {
    if (!audio || isPlaying) return;

    audio.play();
    isPlaying = true;
    }

    //start playing, update button label to PLAY
    function stopAudio() {
    if (!audio || !isPlaying) return;

    audio.pause();
    isPlaying = false;
    }
    }
    {
    //create a hidden <audio> element to play the src mp3 file;
    //configure button click handler to toggle play on/off
    function initAudio1() {
    audio1 = new Audio1();
    audio1.src = ‘2.mp3’;

    isPlaying = false;

    buttonId = ‘#m1-custom-audio-demo2-playstop1-btn’;
    $(buttonId).click(toggleAudio1);

    //stop audio when changing browser page or click home btn
    $(window).bind(‘pagehide’,stopAudio1);
    }

    function toggleAudio1() {
    if (isPlaying) {
    stopAudio1();
    } else {
    playAudio1();
    }
    }

    //start playing, update button label to STOP
    function playAudio1() {
    if (!audio1 || isPlaying) return;

    audio1.play();
    isPlaying = true;
    }

    //start playing, update button label to PLAY
    function stopAudio1() {
    if (!audio1 || !isPlaying) return;

    audio1.pause();
    isPlaying = false;
    }

    #334151

    tony
    Member

    awaiting 4 help from the response team…

Viewing 4 posts - 1 through 4 (of 4 total)
Reply To: Playing Multiple Audio

You must be logged in to post in the forum log in