Я пытаюсь создать приложение в 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. Я хочу остановить / приостановить проигрыватель при нажатии кнопки «назад».
Edit:
Я попробовал это:
var applicationModule = require("application");
var AndroidApplication = applicationModule.android;
var activity = AndroidApplication.foregroundActivity;
activity.onBackPressed = function () {
console.log('Back button pressed.')
};
но выдает ошибку onBackPressed
не найдено.
TypeError: Невозможно установить свойство 'onBackPressed' из неопределенного