javascript - Audio shows 'Invalid source' when linking to a file on local machine using FileOpenPicker -


i'm trying write js windows app. have button on first page, , click event handler code follows:

function picksingleaudiofile(args) { document.getelementbyid("output").innertext += "\n" + this.id + ": ";

    // create picker object , set options     var openpicker = new windows.storage.pickers.fileopenpicker();     openpicker.viewmode = windows.storage.pickers.pickerviewmode.thumbnail;     openpicker.suggestedstartlocation = windows.storage.pickers.pickerlocationid.musiclibrary;     openpicker.filetypefilter.replaceall([".mp3"]);      // open picker user pick file     openpicker.picksinglefileasync().then(function (file) {         if (file) {             // application has read/write access picked file             winjs.log && winjs.log("picked file: " + file.name, "sample", "status");             document.getelementbyid("output").innertext += "you picked " + file.name + " " + file.path;              // save file audio tag , load             var audtag = document.createelement('audio');             audtag.setattribute("id", "audtag");             audtag.setattribute("controls", "true");             audtag.setattribute("msaudiocategory", "backgroundcapablemedia");             audtag.setattribute("src", "\"" + file.path + "\"");             document.getelementbyid("output").appendchild(audtag);             audtag.load();         } else {             // picker dismissed no selected file             winjs.log && winjs.log("operation cancelled.", "sample", "status");         }     }); } 

the path "d:\songs\song1.mp3" or "\network-share\my music\song name.mp3" "invalid source" error when trying load file.

at first glance, this:

audtag.setattribute("src", "\"" + file.path + "\""); 

should instead this:

audtag.setattribute("src", file.path); 

it's not clear why adding backslashes. however, depending on doing , based on samples i've seen, you'd better off doing this:

var filelocation = window.url.createobjecturl(file, { onetimeonly: true }); audtag.setattribute("src", filelocation); 

you might check out "playback manager msaudiocategory sample" windows dev center more ideas.


Comments

Popular posts from this blog

how to proxy from https to http with lighttpd -

android - Automated my builds -

python - Flask migration error -