【问题标题】:How to extract id3 tag from locally uploaded mp3 by fileReference? (AS3)如何通过fileReference从本地上传的mp3中提取id3标签? (AS3)
【发布时间】:2014-07-23 05:33:58
【问题描述】:

在 AS3(用于闪存)中,我们可以使用 FileReference 类浏览本地 mp3 文件并将数据传递给 ByteArray。 但是,这种方式如何提取id3标签呢?

(有一个外部库http://www.emanuelz.com.mx/blog/parsing-local-mp3-with-filereference-and-audiofx-library-106 可以将字节数组解析为声音对象,但是缺少 id3 标签。当您调用 sound.id3.songName 时,它​​返回 NULL。)

【问题讨论】:

    标签: actionscript-3 flash id3


    【解决方案1】:

    您应该加载那个ByteArray,然后创建一个新的Sound 对象,在其上创建一个ID3 事件监听器,然后调用loadCompressedDataFromByteArray(),这将使Flash 将加载的文件解析为MP3,如果它有 ID3 标签,事件将被调度,允许您读取 id3 数据。

    var themp3:Sound=new Sound();
    themp3.addEventListener(Event.ID3,getid3);
    themp3.loadCompressedDataFromByteArray(thefile,thefile.length);
    // thefile is the ByteArray in question
    function getid3(e:Event):void {
        if (e.target is Sound) {
            var s:Sound=e.target as Sound;
            trace(s.id3.songName);
        }
    }
    

    【讨论】:

    • 好问题。还有另一种更高级/手动的方法(字节读取),我稍后会添加作为答案(以防未来的读者需要它)。为什么?只是 Flash 的 ID3 解析器不能很好地处理某些事情,例如日语 .songName 将是 □□□□ 而不是 チェリ
    猜你喜欢
    • 2011-07-02
    • 1970-01-01
    • 1970-01-01
    • 2011-01-06
    • 1970-01-01
    • 2011-09-02
    • 1970-01-01
    • 2012-02-11
    • 2011-09-14
    相关资源
    最近更新 更多