Search code examples
ionic-frameworkionic2cordova-pluginshybrid-mobile-app

Where do i put the static sound files in ionic2 app?


i'm trying to play some sound files from button click in ionic2 app using mediaplugin http://ionicframework.com/docs/v2/native/mediaplugin/

const file = new MediaPlugin('path/to/file.mp3', onStatusUpdate);

i have the 'click.wav' file in '/src/assets/sound/' directory, now how do the access this file in the MediaPlugin() ?? and am i putting the file in the right directory?

Thanks for the help


Solution

  • I suggest you to use cordova.file.externalDataDirectory then you can find your sound file on the phone under Android/data/yourapplication/files folder.

    this.filePath = cordova.file.externalDataDirectory;
    
    this.mediaPlugin = new MediaPlugin(this.filePath + this.directoryName + "/" + this.actualAudioFileName);
    

    You can start a playback with the following code, after you already recorded one

    this.mediaPlugin.play();
    

    Check this pretty good tutorial.

    Edit: Here you can check path of directories, if you want to create a cross platform application