Tuesday, 19 January 2016

Post 39: Add audio to ionic app

ionic start IonicProject blank
cd IonicProject
ionic platform add android
cordova plugin add org.apache.cordova.media
ng-cordova.js in your www/js folder

Inject the dependency:
var example = angular.module('starter', ['ionic', 'ngCordova'])

Add a new controller in app.js:
example.controller("ExampleController", function($scope, $cordovaMedia, $ionicLoading) { $scope.play = function(src) { var media = new Media(src, null, null, mediaStatusCallback); $cordovaMedia.play(media); } var mediaStatusCallback = function(status) { if(status == 1) { $ionicLoading.show({template: 'Loading...'}); } else { $ionicLoading.hide(); } } });

in index.html add in the header:
<script src="js/ng-cordova.min.js"></script> <script src="cordova.js"></script> <script src="js/app.js"></script>

In Index.html add in the body (you have to use "android_asset"):

<ion-content ng-controller="ExampleController"> <button class="button" ng-click="play('/android_asset/www/test.mp3')">Play from file system</button> </ion-content>



No comments:

Post a Comment

Tweet