在iOS中这是标准的。但是在Android上,当我在应用程序中播放aution并关闭应用程序时,音频仍在播放。我怎么能阻止这个?
这就是我所拥有的:
vid = document.getElementById("audio2");
$scope.$on('$ionicView.beforeLeave', function(){
vid.pause();
vid.currentTime = 0;
});
$scope.$on('$ionicView.afterEnter', function(){
vid.pause();
vid.currentTime = 0;
});
vid.onended = function() {
$timeout(function() {
$scope.pause = true;
}, 0);
}
$scope.pause = true;
$scope.playAudio = function() {
vid.play();
$scope.pause = false;
}
$scope.pauseAudio = function() {
vid.pause();
$scope.pause = true;
}
答案 0 :(得分:0)
这取决于您希望应用的行为方式,但您可以使用cordova的 resume 和暂停事件来停止/关闭您的应用并在进入时启动它你的应用再次:
function onLoad() {
document.addEventListener("deviceready", onDeviceReady, false);
}
function onDeviceReady() {
document.addEventListener("resume", onResume, false);
document.addEventListener("pause", onPause, false);
}
// called when entering your app
function onResume() {
var scope = angular.element(document.getElementById('your view element')).scope();
scope .playAudio();
}
// called when leaving your app
function onPause() {
var scope = angular.element(document.getElementById('your view element')).scope();
scope.pauseAudio();
}