【发布时间】:2019-06-19 08:09:24
【问题描述】:
我正在尝试在nativescript-vue 中构建一个包含音频内容的应用程序。我有一个函数在页面为mounted() 时被调用:
this.player = new TNSPlayer();
const playerOptions = {
audioFile: this.audioLink,
loop: false,
autoplay: false,
};
this.player
.initFromUrl(playerOptions)
.then((res) => {
console.log(res);
})
.catch((err) => {
console.log("something went wrong...", err);
});
this.checkInterval = setInterval(() => {
this.player.getAudioTrackDuration().then(duration => {
// iOS: duration is in seconds
// Android: duration is in milliseconds
let current = this.player.currentTime
if (isIOS) {
duration *= 1000
current *= 1000
}
this.currentTime = current;
this.totalTime = duration;
this.progress = Math.ceil(current / duration * 100);
this.isPlaying = this.player.isAudioPlaying()
});
}, 200)
我需要知道音频播放器何时准备就绪,以便显示播放/暂停按钮。我还需要检查按下 android 的后退按钮时调用的事件。
目前,即使单击 android 的后退按钮,我的音频也会继续播放。我想在按下后退按钮时停止/暂停播放器。
编辑: 我试过这个:
var applicationModule = require("application");
var AndroidApplication = applicationModule.android;
var activity = AndroidApplication.foregroundActivity;
activity.onBackPressed = function () {
console.log('Back button pressed.')
};
但这会引发错误onBackPressed not found。
TypeError: 无法设置未定义的属性“onBackPressed”
【问题讨论】:
标签: android nativescript nativescript-vue