我有一个可以播放离线播放列表的应用程序,它可以正常工作,但是如果您在短时间内多次单击某个曲目,它们会相互播放,如果再给它第二秒钟再单击,则可以正常工作在同一轨道上,我认为由于正在使用异步功能播放音频,因此当您第二次或第三次单击轨道时,第一次单击的轨道尚未启动。如您所见,我已经尝试计算异步功能的速度,并且我认为它所花费的时间要长于鼠标单击(运行仿真器)的延迟时间,我的问题是我可以修复此错误!!
注意:我正在使用博览会音频,这是链接:https://docs.expo.io/versions/latest/sdk/audio/
import base64
import requests
import json
url = "https://vision.googleapis.com/v1/images:annotate"
querystring = {"key":".........."}
headers = {
'Content-Type': "application/json",
}
def encode_image(image_path):
with open(image_path, "rb") as image_file:
return base64.b64encode(image_file.read())
def image_request(image_path):
payload = '{ \"requests\":[ { \"image\":{ \"content\":\"'+encode_image(image_path).decode('utf-8')+'" }, \"features\":[ { \"type\":\"TEXT_DETECTION\" } ] } ]}'
response = requests.request("POST", url, data=payload, headers=headers, params=querystring)
return response.text
当您单击曲目时,playtrack()会被调用
async _loadNewPlaybackInstance(playing, index) {
var t0 = performance.now();
if (this.playbackInstance != null) {
this
.playbackInstance
.unloadAsync();
this
.playbackInstance
.setOnPlaybackStatusUpdate(null);
this.playbackInstance = null;
}
// const link = 'dangerAlarm.mp3'
const source = PlayList[this.index].uri;
const initialStatus = {
// Play by default
shouldPlay: playing,
// Control the speed
rate: 1.0,
// Correct the pitch
shouldCorrectPitch: true,
// Control the Volume
volume: 1.0,
// mute the Audio
isMuted: false
};
var t2= performance.now();
const {sound, status} = await Audio
.Sound
.createAsync(source, initialStatus, this._onPlaybackStatusUpdate);
this.playbackInstance = sound;
var t3 = performance.now();
var t1 = performance.now();
console.log(t1-t0);
console.log(t3-t2);
}