JMF核心框架支持不同媒体(如:音频输出和视频输出)间的时钟同步。它是一个标准的扩展框架,允许用户制作纯音频流和视频流。详细介绍
   java代码
- import java.io.File;
 - import java.text.SimpleDateFormat;
 - import java.util.Calendar;
 - import javax.media.Format;
 - import javax.media.Manager;
 - import javax.media.Player;
 - import javax.media.PlugInManager;
 - import javax.media.format.AudioFormat;
 - public class MyTest {
 - /**
 - * @param args
 - * @throws Exception
 - */
 - public static void main(String[] args) throws Exception {
 - MyTest.Play("D:\\test.mp3");
 - }
 - // 播放音频文件
 - public static void Play(String fileurl) {
 - try {
 - Format inMp3 = new AudioFormat(AudioFormat.MPEGLAYER3);
 - Format outLinear = new AudioFormat(AudioFormat.LINEAR);
 - PlugInManager.addPlugIn(
 - "com.sun.media.codec.audio.mp3.JavaDecoder",
 - new Format[] { inMp3 }, new Format[] { outLinear },
 - PlugInManager.CODEC);
 - File file = new File(fileurl);
 - Player player = Manager.createPlayer(file.toURI().toURL());
 - player.start();
 - Thread.sleep(500);
 - double seconds = player.getDuration().getSeconds();
 - System.out.println("MediaTime:" + seconds);
 - System.out.println("MediaTime:" + getTime(seconds));
 - } catch (Exception e) {
 - e.printStackTrace();
 - }
 - }
 - public static String getTime(double time) {
 - int millis = Integer.parseInt(String.valueOf(Math.round(time)));
 - Calendar cal = Calendar.getInstance();
 - cal.set(0, 0, 0, 0, 0, millis);
 - SimpleDateFormat sdf = new SimpleDateFormat("HH:mm:ss");
 - return sdf.format(cal.getTime());
 - }
 - }
 






 阿云:
1F / 2014-04-28 14:44:24
好实用的内容,学习一下
2F / 2015-09-19 22:49:20
牛。能跑通