SoundManager2 - 使用 RTMP 不显示持续时间

SoundManager2 - using RTMP not displaying duration

本文关键字:显示 持续时间 RTMP 使用 SoundManager2      更新时间:2023-09-26

我正在使用SoundManager2通过RTMP流式传输mp3音频。问题是持续时间没有生成,并且始终为 0

var sound = soundManager.createSound({
            id: 'soundid',
            serverURL: 'rtmp://server/',
            url: 'file.mp3',
            autoLoad: true,
            autoPlay: false,
            onload: function() {
                console.log("DURATION: ", this.duration);
            },
            whileplaying: function() {
                console.log(this.duration);
            },
            volume: 100
        }).play();

使用 RTMP 可以获得持续时间吗?我也试过durationEstimate,这也显示 0。

默认情况下,带有 RTMP 的 Soundmanager2 不会计算持续时间,相比之下,您应该将其(以微秒为单位)作为参数提供,否则,您将无法查找 (SetPosition(value)):

var sound = soundManager.createSound({
            id: 'soundid',
            serverURL: 'rtmp://server/',
            url: 'file.mp3',
            duration: 300000,//example for a 5 minutes song
            autoLoad: true,
            autoPlay: false,
            onload: function() {
                console.log("DURATION: ", this.duration);
            },
            whileplaying: function() {
                console.log(this.duration);
            },
            volume: 100
        }).play();

如果您没有mp3音乐的持续时间,请尝试使用mp3的ID3元数据获取它(您可以使用javascript获取它们)。