A Flash Developer Resource Site

Results 1 to 5 of 5

Thread: bitrate in flash, and detect fast mp3s

  1. #1
    Member
    Join Date
    Jul 2001
    Posts
    91

    bitrate in flash, and detect fast mp3s

    I am loading mp3s locally on the hd and use this code to check the mp3 bitrate. *Note, flash does not correctly handle many mp3s, it adjusts the length of the song to make the bitrate a standard 64, 80, 128 etc. This normally does not sound wrong, but other times, when the frequency is not the flash standard(11.025, 22.05, and 44.1), flash changes the pitch of the song, which this script detects. If flash only loads half a second of a 2 minute song this script detects it.

    PHP Code:
    var btr Math.floor((song.getBytesTotal()*8/1000)/(song.duration/1000));
    if (
    btr 400) {
    getURL("javascript: alert('Flash failed to load the song you selected.');");
    } else {
    if (
    btr 59 == || btr 88 == 0) {
    // if bitrate == 59,88,118,176,352 flash has messed up
    getURL("javascript: alert('Flash may have interpreted this song wrong. \\rPlayback may be too fast or too slow.\\r\\rThis is caused byt the mp3\\'s frequency setting.\\rOnly the frequencies 11.025, 22.05, and 44.1 will work.');");
    }
    // play "song" now

    Remove the space between java and script
    Last edited by spacether; 01-24-2004 at 03:34 AM.

  2. #2
    Moderator
    Join Date
    Apr 2001
    Location
    Akron OH, USA
    Posts
    4,841
    thanks for posting this script.

    I wonder if you can modify this to work with streamed mp3 delivered from a web server.

    Code:
    var btr = Math.floor((song.getBytesTotal()*8/1000)/(song.duration/1000));
    For streamed mp3, the duration property only reflects amount loaded not total duration. So I dont think the code above will work for streamed mp3.

    maybe the following could be part of a solution for detecting bitrate of streamed mp3, assuming the duration property is updated in sync with getBytesLoaded();

    Code:
    var btr = Math.floor((song.getBytesLoaded()*8/1000)/(song.duration/1000));
    Alternatively you could use a server side process to read the mp3's bitrate and verify during upload or before flash attempts download.
    aviarts.com - web development and flash development

  3. #3
    Moderator
    Join Date
    Apr 2001
    Location
    Akron OH, USA
    Posts
    4,841
    shouldnt this be divided by 1024 instead of 1000?

    song.getBytesTotal()*8/1000

    should be

    song.getBytesTotal()*8/1024

    because there are 1024 bits in one kbit.
    aviarts.com - web development and flash development

  4. #4
    Member
    Join Date
    Jul 2001
    Posts
    91
    Hypothetically it should be that way, but when I tested by dividing by 1024, the code returned wrong results; using 1000 returns correct bitrates.

  5. #5
    Member
    Join Date
    Jul 2001
    Posts
    91
    I am still loading mp3s locally on the HD I just got the strangest results. Apparently, on the hd at least, (I'm using XP, browser does not matter) Loading the mp3 streamed and non-streamed returned different durations and bitrate results.
    Using: Math.round((song.getBytesTotal()*8/1000)/(song.duration/1000)) returns:
    non-stream: 88
    stream: 64
    file: 64 kbps, 32 khz
    And the song is played too fast both times, but when it is streamed, the correct length of the mp3 is detected, and it returns the correct bitrate, 64 kbps.

    Other times(though rarely), a normal mp3, 128kbps 44.1 khz, or 96 kbps 44.1 khz(just examples), will load only a fraction of a second non-streaming, and will load normally and perfectly streaming.

    Remember, all these results are for local mp3 browsing on the hd.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  




Click Here to Expand Forum to Full Width

HTML5 Development Center