java通过url播放远程mp3及获取播放时长

直接代码


public class ReadMp3 {
	private String _songName;
	ReadMp3(String songName) throws IOException, Exception{
		_songName = songName;
		URL url = new URL("http://fs.w.kugou.com/201901082013/9ec2463ebd15378341c24d982ccf183f/G009/M00/16/13/SQ0DAFUWmN-ALX4LADv-LPZ8GHs526.mp3");
		URLConnection con = null;
		try{
			con = url.openConnection();
		}catch(IOException e){
			e.printStackTrace();
		}
		
		BufferedInputStream bis = new BufferedInputStream(con.getInputStream());
		Bitstream bt = new Bitstream(bis);
		
                //获取mp3时间长度
		Header header = bt.readFrame();
                int mp3Length = con.getContentLength();
		int time = (int) header.total_ms(mp3Length);
		System.out.println(time / 1000);
 
                Player player = new Player(bis);
		player.play();
	}
	
	public static void main(String[] args) throws Exception{
		ReadMp3 mp3 = new ReadMp3("贝加尔湖畔");
	}
}

在这里插入图片描述

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值