zoukankan      html  css  js  c++  java
  • 下载一首网络歌曲 该歌曲地址获取不到歌曲的大小,但可以正常播放

    有些歌曲的下载地址,无法获得歌曲的大小:但可以正常播放

    player.reset();
    player.setDataSource(currSoundFileUrl);
    System.out.println("yuan网址:" + currSoundFileUrl);
    player.setAudioStreamType(AudioManager.STREAM_MUSIC);
    player.prepare();
    soundLength = player.getDuration();

    soundLength有时获取不到歌曲的大小,为0;

    这时最好是下载到本地再读取本地歌曲,用完时将歌曲删除:

    下面是下载该类歌曲的代码:


    new AsyncTask<Void, Void, Void>() {


    @Override
    protected Void doInBackground(Void... params) {


    try {
    URL url = new URL("http://218.94.93.115:8002/audioservernews/news/file2/news/tqh/air/download/52579f60c8f27d5f81c3d8b2?rate=wma/");


    HttpURLConnection conn = (HttpURLConnection) url.openConnection();
    conn.setRequestProperty("Accept-Encoding", "identity"); 
    int lene = conn.getContentLength();

    InputStream is = conn.getInputStream();

    BufferedInputStream bis = new BufferedInputStream(is);
    int len = -1;
    byte[] buf = new byte[1024 * 8];

    File file = new File("/mnt/sdcard/hello.wma");

    RandomAccessFile raf = new RandomAccessFile(file, "rw");
    raf.seek(0);

    while((len = bis.read(buf)) != -1){
    raf.write(buf, 0, len);
    }

    System.out.println("hello>>" + lene);


    } catch (MalformedURLException e) {
    e.printStackTrace();
    } catch (IOException e) {
    e.printStackTrace();
    }


    源码下载



    return null;
    }
    }.execute();



  • 相关阅读:
    jmeter bean shell断言加密的响应信息(加密接口测试二)
    java ID3算法
    MPI常用函数
    数据结构——单链表
    RBM代码注释c++
    MPI_一个简单的消息传递
    电路测试
    java KNN算法
    [转]矩阵分解在推荐系统中的应用
    java EM算法
  • 原文地址:https://www.cnblogs.com/fuhaots2009/p/3373606.html
Copyright © 2011-2022 走看看