React native 在React Native expo中构建媒体播放器并获得歌曲的持续时间
我在React Native expo中实现一个媒体播放器。我已经设计了播放器、播放歌曲、下一首歌曲和上一首歌曲功能,但是我在获取歌曲的持续时间时遇到了问题,以便能够使用进度条显示歌曲的进度 我已经浏览了一遍,没有找到任何关于如何获取文件持续时间或如何获取任何可以帮助我实现进度条的信息的信息。任何想法都是非常受欢迎的 我正在试验的代码:React native 在React Native expo中构建媒体播放器并获得歌曲的持续时间,react-native,audio,expo,React Native,Audio,Expo,我在React Native expo中实现一个媒体播放器。我已经设计了播放器、播放歌曲、下一首歌曲和上一首歌曲功能,但是我在获取歌曲的持续时间时遇到了问题,以便能够使用进度条显示歌曲的进度 我已经浏览了一遍,没有找到任何关于如何获取文件持续时间或如何获取任何可以帮助我实现进度条的信息的信息。任何想法都是非常受欢迎的 我正在试验的代码: //从Expo.Audio.Sound创建新对象 this.soundObject=新的Audio.Sound(); 等待这个.soundObject.load
//从Expo.Audio.Sound创建新对象
this.soundObject=新的Audio.Sound();
等待这个.soundObject.loadAsync(url);
等待此消息。soundObject.playsync();
getCurrentItemArtistName=()=>{
返回此.list[this.index].artistname;
};
getCurrentItemCover=()=>{
返回此.list[this.index].cover;
};
提前谢谢你这对我很有用。但它是在
声音类组件中使用的
CurrentDuration = async () => {
const Mill = await this.soundObject.getStatusAsync();
let p = Mill.positionMillis;
return {curr:p};
};
这对我有用。但它是在声音类组件中使用的
CurrentDuration = async () => {
const Mill = await this.soundObject.getStatusAsync();
let p = Mill.positionMillis;
return {curr:p};
};
但是,我不确定您是否仍然感兴趣,因为下面是一种获取持续时间的方法
const sound = new Audio.Sound();
try {
const track = await sound.loadAsync(require('../../models/smw_bonus_game_end.mp3'));
console.log(track.durationMillis); // Prints the duration in milliseconds
} catch (err) {
console.log(err);
};
加载文件后,您可以获得持续时间
const sound = new Audio.Sound();
try {
const track = await sound.loadAsync(require('../../models/smw_bonus_game_end.mp3'));
console.log(track.durationMillis); // Prints the duration in milliseconds
} catch (err) {
console.log(err);
};
可以在对象中找到其他信息。使用下面相同的代码,只需尝试仅打印常量轨迹:
它将按如下方式打印对象:
Object {
"didJustFinish": false,
"durationMillis": 3108,
"hasJustBeenInterrupted": false,
"isBuffering": false,
"isLoaded": true,
"isLooping": false,
"isMuted": false,
"isPlaying": false,
"pitchCorrectionQuality": "Varispeed",
"playableDurationMillis": 3108,
"positionMillis": 0,
"progressUpdateIntervalMillis": 500,
"rate": 1,
"shouldCorrectPitch": false,
"shouldPlay": false,
"uri": "THE URI OF THE FILE IN YOUR DEVICE",
"volume": 1,
}
还有很多其他信息,如果你需要一些具体的信息,请告诉我
我希望这有帮助
干杯,我不确定您是否仍然感兴趣,但是,下面是一种获得持续时间的方法
const sound = new Audio.Sound();
try {
const track = await sound.loadAsync(require('../../models/smw_bonus_game_end.mp3'));
console.log(track.durationMillis); // Prints the duration in milliseconds
} catch (err) {
console.log(err);
};
加载文件后,您可以获得持续时间
const sound = new Audio.Sound();
try {
const track = await sound.loadAsync(require('../../models/smw_bonus_game_end.mp3'));
console.log(track.durationMillis); // Prints the duration in milliseconds
} catch (err) {
console.log(err);
};
可以在对象中找到其他信息。使用下面相同的代码,只需尝试仅打印常量轨迹:
它将按如下方式打印对象:
Object {
"didJustFinish": false,
"durationMillis": 3108,
"hasJustBeenInterrupted": false,
"isBuffering": false,
"isLoaded": true,
"isLooping": false,
"isMuted": false,
"isPlaying": false,
"pitchCorrectionQuality": "Varispeed",
"playableDurationMillis": 3108,
"positionMillis": 0,
"progressUpdateIntervalMillis": 500,
"rate": 1,
"shouldCorrectPitch": false,
"shouldPlay": false,
"uri": "THE URI OF THE FILE IN YOUR DEVICE",
"volume": 1,
}
还有很多其他信息,如果你需要一些具体的信息,请告诉我
我希望这有帮助
干杯,到目前为止,您已经知道了吗?世博会的音频对你有用吗?到目前为止你知道了吗?世博会的音频对你有用吗?