ionic使用cordovaMedia、cordovaFile和cor 2016-12-22 app ionic **首先安装cordovaNativeAudio和cordovaFileTransfer插件** ``` cordova plugin add cordova-plugin-media cordova plugin add cordova-plugin-file cordova plugin add cordova-plugin-file-transfer ``` **配置config.xml** ``` ``` **js代码如下** ``` .controller('AudioInterNetCtrl', function ($scope, $cordovaMedia, $cordovaFileTransfer,$ionicPlatform,$cordovaFile,$timeout) { $scope.params={url:''}; $scope.play = function () { var fileName=new Date().getTime(); document.addEventListener('deviceready', function () { var url = $scope.params.url; var targetPath = cordova.file.cacheDirectory + fileName+".mp3"; var trustHosts = true; var options = {}; $cordovaFileTransfer.download(url, targetPath, options, trustHosts) .then(function(result) { // Success var media = $cordovaMedia.newMedia(targetPath); media.play(); }, function(err) { // Error }, function (progress) { $timeout(function () { $scope.downloadProgress = (progress.loaded / progress.total) * 100; }); }); }, false); }; }) ``` **html代码如下** ``` {{downloadProgress}} 点击播放在线音乐 ```