How to get audio files on my phone using Ionic 2 C

2020-05-06 00:50发布

问题:

I have tried the Ionic mediaPlugin

import { MediaPlugin } from 'ionic-native';

var file = new MediaPlugin('path/to/file.mp3');

I'm still confused on how to do that. All I want to do is to create something like a media player, that gets all the audio on a users android phone, and to play and pause it too.

回答1:

Check this tutorial first it will guide you. However check this too, it will tell you where you have to store your data.

If you do it on android, you should use externalDataDirectory.

  this.filePath = cordova.file.externalDataDirectory;

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

After this you can find your data under the following folder on your phone Android/data/yourApplicationId/files/yourDirectoryName