如何使用 Ionic 2 Cordova 插件在手机上获取音频文件? [英] How to get audio files on my phone using Ionic 2 Cordova plugins?
问题描述
我已经尝试过 Ionic mediaPlugin
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.
推荐答案
检查这个 教程 首先它会指导你.但是请检查 this,它会告诉您必须将数据存储在哪里.
Check this tutorial first it will guide you. However check this too, it will tell you where you have to store your data.
如果你在android上做,你应该使用externalDataDirectory.
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);
之后,您可以在手机的以下文件夹下找到您的数据Android/data/yourApplicationId/files/yourDirectoryName
After this you can find your data under the following folder on your phone Android/data/yourApplicationId/files/yourDirectoryName
这篇关于如何使用 Ionic 2 Cordova 插件在手机上获取音频文件?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!