简体   繁体   English

ng cordova media plugin stop方法不起作用

[英]ng cordova media plugin stop method not working

iam created simple ionic audio app .its play function is work correctly but stop function not working.this is the code please help to fix this this is controller 我创建简单的离子音频应用程序。播放功能是正常工作但停止功能不工作。这是代码请帮助解决这个这是控制器

 angular.module('starter', ['ionic', 'ngCordova']) .controller("ExampleController", function($scope, $ionicPlatform, $cordovaMedia, $ionicLoading) { $ionicPlatform.ready(function() { $scope.play = function() { var media = new Media(src, null, null, mediaStatusCallback); $cordovaMedia.play(media); }; $scope.pause = function() { media.pause(); }; $scope.stop = function() { media.stop(); }; var mediaStatusCallback = function(status) { if(status == 1) { $ionicLoading.show({template: 'Loading...'}); } else { $ionicLoading.hide(); } } }); }) 

and this is the html code : 这是html代码:

  <ion-pane> <ion-header-bar class="bar-stable"> <h1 class="title">Ionic Blank Starter</h1> </ion-header-bar> <ion-content> <button class="button" ng-click="play('http://www.stephaniequinn.com/Music/Commercial%20DEMO%20-%2013.mp3')">Play from internet</button> <button class="button" ng-click="stop()">Stop</button> </ion-content> </ion-pane> 

Your media variable is local . 您的媒体变量是本地的 So in stop function media is undefined or not the same. 所以在停止功能媒体是未定义或不相同。

Moreover why are you use methods in different ways? 此外,为什么你以不同的方式使用方法? I think you should use the same (eg media.play() or $cordovaMedia.stop(media); if it's possible) 我认为你应该使用相同的(例如media.play()或$ cordovaMedia.stop(media);如果可能的话)

Your variable var media is out of the scope of $scope.pause and $scope.stop. 您的变量var media超出了$ scope.pause和$ scope.stop的范围。 Try declaring it outside on the $scope.play function like so.. 尝试在$ scope.play函数外面声明它,就像这样..

 angular.module('starter', ['ionic', 'ngCordova']) .controller("ExampleController", function($scope, $ionicPlatform, $cordovaMedia, $ionicLoading) { $ionicPlatform.ready(function() { var media = new Media(src, null, null, mediaStatusCallback); $scope.play = function() { $cordovaMedia.play(media); }; $scope.pause = function() { media.pause(); }; $scope.stop = function() { media.stop(); }; var mediaStatusCallback = function(status) { if(status == 1) { $ionicLoading.show({template: 'Loading...'}); } else { $ionicLoading.hide(); } } }); }) 

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

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