Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,41 @@ var LibraryHTML5Audio = {
},

html5audio_sound_load: function (player_id, url) {
AUDIO.player[player_id].src = UTF8ToString(url);
try {
var filePath = UTF8ToString(url);

if( filePath.indexOf("http") == 0 ) {
AUDIO.player[player_id].src = filePath;
}else{

//console.log("file path is" + filePath);

var data = FS.readFile(filePath, { encoding: 'binary' });

var ext = filePath.split('.').pop();

var stats = FS.stat(filePath)
var fileSizeInBytes = stats.size;

var tag = ext; //this covers most types
if( ext == mp3 ){
tag = 'mpeg';
}else if( ext == 'oga'){
tag = 'ogg';
}else if( ext == 'weba'){
tag = 'webm';
}

const blob = new Blob([data], { type: 'audio/' + tag });
const audioSrc = URL.createObjectURL(blob);

AUDIO.player[player_id].src = audioSrc;
}

} catch (error) {
console.error('Error reading file:' + filePath + " " + error);
}

},

html5audio_sound_play: function (player_id, multiplay, volume, speed, pan, offset) {
Expand Down
16 changes: 10 additions & 6 deletions addons/ofxEmscripten/src/ofxEmscriptenSoundPlayer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -37,15 +37,19 @@ ofxEmscriptenSoundPlayer::~ofxEmscriptenSoundPlayer(){
html5audio_sound_free(player_id);
}

bool ofxEmscriptenSoundPlayer::load(const std::filesystem::path& fileName, bool stream){
html5audio_sound_load(player_id, ofToDataPath(fileName).c_str());
bool ofxEmscriptenSoundPlayer::load(const of::filesystem::path& filePath, bool stream){
auto soundFilePath = filePath.string();
if ( soundFilePath.substr(0, 7) != "http://" && soundFilePath.substr(0, 8) != "https://"){
soundFilePath = ofToDataPath(soundFilePath);
}
html5audio_sound_load(player_id, soundFilePath.c_str());
return true;
}

bool ofxEmscriptenSoundPlayer::load(const std::string& fileName, bool stream){
html5audio_sound_load(player_id, fileName.c_str());
return true;
}
//bool ofxEmscriptenSoundPlayer::load(const std::string& fileName, bool stream){
// html5audio_sound_load(player_id, fileName.c_str());
// return true;
//}

void ofxEmscriptenSoundPlayer::unload(){
html5audio_sound_free(player_id);
Expand Down
4 changes: 2 additions & 2 deletions addons/ofxEmscripten/src/ofxEmscriptenSoundPlayer.h
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,8 @@ class ofxEmscriptenSoundPlayer: public ofBaseSoundPlayer {
ofxEmscriptenSoundPlayer();
~ofxEmscriptenSoundPlayer();

bool load(const std::filesystem::path& fileName, bool stream = false);
bool load(const std::string& fileName, bool stream = false);
bool load(const of::filesystem::path& fileName, bool stream = false);
// bool load(const std::string& fileName, bool stream = false);
void unload();
void play();
void stop();
Expand Down