简体   繁体   English

如何使用Ionic 2 Cordova插件在手机上获取音频文件?

[英]How to get audio files on my phone using Ionic 2 Cordova plugins?

I have tried the Ionic mediaPlugin 我已经尝试过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. 我要做的就是创建一个诸如媒体播放器之类的东西,在用户的Android手机上获取所有音频,并播放和暂停它。

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 . 如果您在android上执行此操作,则应使用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 之后,您可以在手机上的以下文件夹中找到数据Android / data / yourApplicationId / files / yourDirectoryName

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM