0
0

Hi guys,

I’m quite new to fmod and am having trouble loading a remote sound file from a url, namely this sound: http://www.freesound.org/data/previews/244/244517_2479316-lq.mp3

I am making an iOS app that can play back audio files from URLs, as I’m querying a database of sound depending on the users location. I am writing my app in Objective C++ and using openframeworks as a framework to build my app (please note I understood they took out the fmod wrapper they had for the ios build of oF, but maybe that is where my problem lies). Anyway I’ve built a VERY simple audio managing class to load and play sound files (with hardcoded URLs) to test wether I could get it too work.

MY PROBLEM IS: I appear to be loading the soundfile correctly as I get this message at the console “FMOD: SystemI::createSoundInternal : filename = http://www.freesound.org/data/previews/244/244517_2479316-lq.mp3 : mode 010000c8″. However when I make a call to play, no sound can be heard! I will post my code below:

soundAgent.h
#pragma once
#include "ofMain.h"
#include "ofxiOS.h"
#include "ofxiOSExtras.h"
#include "fmod.h"
#include "fmod.hpp"
#include "fmod_errors.h"
#include <iostream>
#include <string>
#include <map>**

typedef std::map<std::string, FMOD::Sound*> SoundMap;

class SoundAgent : public ofxiOSApp {
public:
    SoundAgent();
    ~SoundAgent();

    void update();
    void load(const std::string& path);
    void stream(const std::string& path);
    void play();
private:
    void loadOrStream(const std::string& path, bool stream);
    FMOD::System* system;
    FMOD::Sound* sound;
    FMOD::Channel* channel; 
};

soundAgent.mm
#include "soundAgent.h"

SoundAgent::SoundAgent(){
    FMOD::System_Create(&system);
    system->init(100, FMOD_INIT_NORMAL, NULL);
}
SoundAgent::~SoundAgent(){
    system->release();
    system = 0;
}

void SoundAgent::update(){
    system->update();
}
void SoundAgent::load(const std::string& path){
    system->createSound(path.c_str(), FMOD_SOFTWARE | FMOD_2D | FMOD_CREATESTREAM | FMOD_UNICODE, 0, &sound);
}

void SoundAgent::play(){
    system->playSound(FMOD_CHANNEL_FREE, sound, 0, &channel);
}

ofApp.h
#pragma once

#include "ofMain.h"
#include "ofxiOS.h"
#include "ofxiOSExtras.h"
#include "soundAgent.h"

class ofApp : public ofxiOSApp {

    public:
        void setup();
        void update();
        void draw();
        void exit();

        void touchDown(ofTouchEventArgs & touch);
        void touchMoved(ofTouchEventArgs & touch);
        void touchUp(ofTouchEventArgs & touch);
        void touchDoubleTap(ofTouchEventArgs & touch);
        void touchCancelled(ofTouchEventArgs & touch);

        void lostFocus();
        void gotFocus();
        void gotMemoryWarning();
        void deviceOrientationChanged(int newOrientation);

    SoundAgent soundAgent;

};

ofApp.mm
#include "ofApp.h"

void ofApp::setup(){
    soundAgent.load("http://www.freesound.org/data/previews/244/244517_2479316-lq.mp3");
}

void ofApp::update(){
    soundAgent.update();
}

void ofApp::draw(){


}

void ofApp::exit(){

}

void ofApp::touchDown(ofTouchEventArgs & touch){
    soundAgent.play();
}

please note I have tested this method of loading urls with the example ‘playSound’ that comes with the Mac version of FMODEx download and it plays back perfectly.

Any help would be very much appreciated.

Thanks,
Sam

  • You must to post comments
Showing 0 results
Your Answer

Please first to submit.