开发者

SoundManager2 onid3() not firing

开发者 https://www.devze.com 2023-02-05 03:25 出处:网络
I\'m building a simple Javascript jukebox using the latest SoundManager2 for audio playback, with local MP3 files being the source. I\'ve got file loading and playing sorted, and at the moment I\'m tr

I'm building a simple Javascript jukebox using the latest SoundManager2 for audio playback, with local MP3 files being the source. I've got file loading and playing sorted, and at the moment I'm trying to get access to the ID3 info of these MP3 files, but the onid3() callback is not firing. I'm using Flash and have verified that ID3 info is present in the files. Below is my implementation of onid3():

function playNextSongInQueue()
{
    // Get the first element of the songQueue array
    var nextSongInQueue = songQueue.shift();

    // Start playback from the queue
    var jukeboxTune = soundManager.createSound({
        id: 'currentTune',
        url: 'audio/' + nextSongInQueue.name,
        onload: function() {
            this.play();
        },
        onid3: function() {
            alert('ID3 present!');
        },
        onfinish: function() {
            this.destruct();    // Destroy this sound on finish
            songFinish();       // Run the songFinish() function, so decide what to do next
        }
    });

    jukeboxTune.load();
    //jukeboxTune.play();           // The jukebox running!

    songPlaying = true;             // Set songPlaying flag
    updateSongQueueDisplay();       // Refresh the song queue display (for debug)

    return nextSongInQueue.name;
}

The other callbacks work fine, but the onid3() alert never comes up. I even separated the load and play portions of audio playback to see if that helped. SoundManager spots that onid3() is there because it switches usePolicyFile to true - seeing as the MP3s are local I am assuming I don't need to worry about the cross-domain XML file.

Can anybody shed light on why this isn't working? I've scoured Google looking for implementations that work but have come up with nothing helpful. I've seen Jacob Seidelin's pure Javascript workaround but woul开发者_如何学God rather stick with SoundManager if possible, and would rather not use a PHP solution.

Thanks,

Adam


This problem is probably too esoteric for any solid answers, so I decided to investigate possible Javascript solutions outside the SM2 library.

I started with Nihilogic's library for reading ID3v1 tags (at http://blog.nihilogic.dk/2008/08/reading-id3-tags-with-javascript.html), but moved to antimatter15's js-id3v2 library (https://github.com/antimatter15/js-id3v2) as it can read ID3v2 tags. Adapting code from the provided example I have managed to successfully parse the main tags required when the MP3s are loaded via the <input> control.


For local files, i speak of "user local files" (not "server" local files) i get some success with id3v2.js

To get ID3, SM2 need a cross domain on the mp3 host, if it's another domain. Plus i have encountered difficulties with Soundcloud as they redirect MP3 to dynamic Amazon S3 storage... so i have to do a PHP script to guest final URL and then SM2 can get proper crossdomain.xml (Check https://getsatisfaction.com/schillmania/topics/displaying_waveformdata_of_soundcloud_hosted_track_prompts_securityerror_error_2122 )

The problem is both S3 links and local user files (blob) do have a short expiration delay.

Good luck !

0

精彩评论

暂无评论...
验证码 换一张
取 消