Java gets the playback time of AMR duration

Source: Internet
Author: User
/** * Get AMR * * @param file * @return * @throws ioexception/public static long GE
        Tamrduration (file file) throws IOException {Long duration =-1;
        Int[] Packedsize = {12, 13, 15, 17, 19, 20, 26, 31, 5, 0, 0, 0, 0, 0, 0, 0};
        Randomaccessfile randomaccessfile = null;
            try {randomaccessfile = new Randomaccessfile (file, rw);  Long length = File.length ()//file length int pos = 6;//set initial position int framecount = 0;//initial frame number int
            Packedpos =-1; byte[] Datas = new byte[1];//initial data value while (PO
                s <= length) {Randomaccessfile.seek (POS); if (Randomaccessfile.read (datas, 0, 1)!= 1) {duration = length > 0?
                    ((length-6)/650): 0;
                Break } Packedpos = (Datas[0] >> 3) & 0x0f;
                POS + + Packedsize[packedpos] + 1;
            framecount++;
        /////////////////////////////////////////////////////Duration + + Framecount * 20;//Frame number *20
            finally {if (randomaccessfile!= null) {randomaccessfile.close ();
    } return duration; }

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.