Create a simple player by using cordova media plugin


#1

Hi,

I’m trying to create an app just for listening audio files. So I need to set up a very simple audio player that plays, gets pause and stops.

I’m a really beginner for using « Ionic », but I already know how to build with html/css. For days, I try to find a solution by reading the forum and testing my app on my device. But it still doesn’t work.

I’ve already tested by using « cordova native audio plugin » - I’ve followed a very good tuto here http://www.gajotres.net/playing-native-audio-using-ionic-framework-and-cordova/
It works fine but, it seems not possible to get pause ; the player may just play and stop… so, I began to use « cordova media plugin » ; it’s really a nightmare. I finally don’t know how to build the js file, even with doc from Cordova.
Thanks a lot for your help ! :relaxed:
Below copies of my app.js and index.html files.

angular.module(‘test’, [‘ionic’])

.run(function($ionicPlatform) {
$ionicPlatform.ready(function() {
if(window.cordova && window.cordova.plugins.Keyboard) {
cordova.plugins.Keyboard.hideKeyboardAccessoryBar(true);

  cordova.plugins.Keyboard.disableScroll(true);
}
if(window.StatusBar) {
  StatusBar.styleDefault();
}

});
})

.controller(‘AudioCtrl’, function($scope, $ionicPlatform) {

var src = "/audio/muzik1.mp3";
var media = $cordovaMedia.newMedia(src);


$scope.play = function(src) {
	media.play();

}

$scope.pause = function() {
media.pause();
}

$scope.stop = function() {
media.stop();
}

})


index
<link href="lib/ionic/css/ionic.css" rel="stylesheet">
<link href="css/style.css" rel="stylesheet">

<!-- IF using Sass (run gulp sass first), then uncomment below and remove the CSS includes above
<link href="css/ionic.app.css" rel="stylesheet">
-->

<!-- ionic/angularjs js -->
<script src="lib/ionic/js/ionic.bundle.js"></script>

<!-- cordova script (this will be a 404 during development) -->
<script src="cordova.js"></script>

<!-- your app's js -->
<script src="js/app.js"></script>
<ion-view>

<ion-content>

 <h1>Lecteur</h1>
 <button ng-click="play('muzik1.mp3')">Lecture</button>
 <button ng-click="pause()">Pause</button>
 <button ng-click="stop()">Stop</button>

</ion-content>

</ion-view>