如何学习Java的媒体框架的工作时间的.wav? [英] How to learn .wav duration in Java media frame work?

查看:122
本文介绍了如何学习Java的媒体框架的工作时间的.wav?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我tyring合并使用Java媒体框架.wav文件的.mov文件,所以我需要知道他们的时间。我怎样才能做到这一点?任何想法将AP preciated ..

I am tyring to merge an .mov file with a .wav file using java media framework, thus I need to know their duration. How can I do this? Any ideas would be appreciated..

推荐答案

您可以学习使用这种方式(即VitalyVal的第二种方法)声音文件时间:

you can learn the duration of sound files using this way(that is VitalyVal's second way):

  import java.net.URL;

        import javax.sound.sampled.AudioFormat;
        import javax.sound.sampled.AudioInputStream;
        import javax.sound.sampled.AudioSystem;
        import javax.sound.sampled.Clip;
        import javax.sound.sampled.DataLine;

        public class SoundUtils {
            public static double getLength(String path) throws Exception {
                AudioInputStream stream;
                stream = AudioSystem.getAudioInputStream(new URL(path));
                AudioFormat format = stream.getFormat();
                if (format.getEncoding() != AudioFormat.Encoding.PCM_SIGNED) {
                    format = new AudioFormat(AudioFormat.Encoding.PCM_SIGNED, format
                            .getSampleRate(), format.getSampleSizeInBits() * 2, format
                            .getChannels(), format.getFrameSize() * 2, format
                            .getFrameRate(), true); // big endian
                    stream = AudioSystem.getAudioInputStream(format, stream);
                }
                DataLine.Info info = new DataLine.Info(Clip.class, stream.getFormat(),
                        ((int) stream.getFrameLength() * format.getFrameSize()));
                Clip clip = (Clip) AudioSystem.getLine(info);
                clip.close();
                return clip.getBufferSize()
                        / (clip.getFormat().getFrameSize() * clip.getFormat()
                                .getFrameRate());
            }

            public static void main(String[] args) {
                try {

                    System.out
                            .println(getLength("..."));
                } catch (Exception e) {
                    e.printStackTrace();
                }
            }

        }

这篇关于如何学习Java的媒体框架的工作时间的.wav?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆