locked
Play file in audio RRS feed

  • Question

  • Hello!

    If I have access in code to Folder or file - how can I play it in <audio> element?

    I think it should be very popular question.

    Sunday, May 5, 2013 6:35 AM

Answers

  • After you get a return value as "file" from filepicker, convert the result to a fileURL->

                var fileLocation = window.URL.createObjectURL(file, { oneTimeOnly: true });
    

    then you can just set the audio source of a HTML5 audio element->

                    audtag.setAttribute("src", fileLocation);
    
                    audtag.load();

    then you can play it like->

                    audtag.play();

    or if you give the user controls under the audio tag, then you can let them play, pause or stop.
    Sunday, May 5, 2013 2:22 PM

All replies

  • After you get a return value as "file" from filepicker, convert the result to a fileURL->

                var fileLocation = window.URL.createObjectURL(file, { oneTimeOnly: true });
    

    then you can just set the audio source of a HTML5 audio element->

                    audtag.setAttribute("src", fileLocation);
    
                    audtag.load();

    then you can play it like->

                    audtag.play();

    or if you give the user controls under the audio tag, then you can let them play, pause or stop.
    Sunday, May 5, 2013 2:22 PM
  • Thank you. Works!
    Sunday, May 5, 2013 4:23 PM