Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Can JPlayer play file from byte array?

Tags:

jplayer

I am using JPlayer which plays different audio files based on the the user input. Every time a user enters an input, I am calling a REST web service to retrieve the audio file to play. The response from the REST service is a byte[].

What I am trying to achieve is to save this array of byte in memory instead of writing it to a file and use that byte[] for jplayer. I am not sure how to get JPlayer to play a byte[].

var file = [[${audiofile}]]

$(document).ready(function(){                    
    $("#jquery_jplayer_1").jPlayer(
    { 
        ready: function () {                            
            $(this).jPlayer("setMedia",{                                                                
            wav: file
        });
    },

the variable file evaluates to a byte[]. When trying to play the audio, I see the following error in console.

Uncaught TypeError: Object -1,-5,-112,-60,0,3,19,124,-73.......

I will appreciate if somebody has any suggestions.

Thanks

like image 296
javakurious Avatar asked Oct 31 '22 22:10

javakurious


1 Answers

Unfortunately, this feature looks unimplemented right now. From the source code of JPlayer 2.9.2 from line 1945:

    setMedia: function(media) {

        /*  media[format] = String: URL of format. Must contain all of the supplied option's video or audio formats.
         *  media.poster = String: Video poster URL.
         *  media.track = Array: Of objects defining the track element: kind, src, srclang, label, def.
         *  media.stream = Boolean: * NOT IMPLEMENTED * Designating actual media streams. ie., "false/undefined" for files. Plan to refresh the flash every so often.
         */

Please notice the last line. Wish I had better news.

REF: https://github.com/happyworm/jPlayer/blob/master/src/javascript/jplayer/jquery.jplayer.js

Some fellows came close to a solution, but not with JPlayer. REF: How to play audio byte array (not file!) with JavaScript in a browser

like image 184
Drakes Avatar answered Nov 28 '22 12:11

Drakes