gpt4 book ai didi

javascript - 音频 JavaScript

转载 作者:行者123 更新时间:2023-12-03 04:44:22 29 4
gpt4 key购买 nike

我是 ionic 2 的初学者

我使用了音频文件。

   import { Component } from '@angular/core';
import {NavController, AlertController} from 'ionic-angular';
import {LocalNotifications} from 'ionic-native';
import { AudioProvider } from 'ionic-audio';

@Component({
selector: 'page-home',
templateUrl: 'home.html'
})
export class HomePage {

constructor(private _audioProvider: AudioProvider,private navController: NavController) {

}
play(a):any {
var audio=new Audio();
audio.src='https://ia800406.us.archive.org/16/items/JM2013-10-05.flac16/V0/jm2013-10-05-t30-MP3-V0.mp3';
//console.log(audio.currentTime);

if(a === "1")
{
console.log("play")
console.log(audio.currentTime);
audio.play();
console.log(audio.play());
}
if(a === "0"){
console.log("pause");
console.log(audio);
audio.pause();

}
}


}

这是我的模板 世界是你的牡蛎。 玩 暂停

audio.play() 播放音频文件,但无法暂停。请给我建议,谢谢

最佳答案

问题是您没有保留对音频对象的引用。每次单击时,您都会创建新的音频对象,并且会丢失旧的音频对象。所以它仍然继续播放。

export class HomePage {
audio:any;
constructor(private _audioProvider: AudioProvider,private navController: NavController) {
audio = new Audio();
audio.src='https://ia800406.us.archive.org/16/items/JM2013-10-05.flac16/V0/jm2013-10-05-t30-MP3-V0.mp3';
}
play(a):any {
//console.log(audio.currentTime);

if(a === "1")
{
console.log("play")
console.log(audio.currentTime);
audio.play();
console.log(audio.play());
}
if(a === "0"){
console.log("pause");
console.log(audio);
audio.pause();

}
}


}

关于javascript - 音频 JavaScript,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/42932651/

29 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com