WEB开发网
开发学院手机开发Android 开发 Android 流媒体播放器开发实现 阅读

Android 流媒体播放器开发实现

 2010-05-26 15:38:00 来源:WEB开发网   
核心提示:mPlayer.start();return;}current = path;mPlayer = null;new PlayThread(current).start();} catch (Exception e) {}}private void setListener() {if (mPlayer != null)

mPlayer.start();

return;

}

current = path;

mPlayer = null;

new PlayThread(current).start();

} catch (Exception e) {

}

}

private void setListener() {

if (mPlayer != null) {

mPlayer.setOnErrorListener(this);

mPlayer.setOnBufferingUpdateListener(this);

mPlayer.setOnCompletionListener(this);

}

}

/**

* 下载数据,分段下载

* todo:联网方式和分段

* @param mediaUrl

* @param start

* @param end

*/

private void playFromNet(String mediaUrl, int start, int end) {

URLConnection cn = null;

FileOutputStream out = null;

InputStream is = null;

try {

cn = new URL(mediaUrl).openConnection();

cn.connect();

is = cn.getInputStream();

int mediaLength = cn.getContentLength();

if (is == null) {

return;

}

deleteTempFile(true);

DLTempFile = File.createTempFile(TEMP_DOWNLOAD_FILE_NAME,

FILE_POSTFIX);

out = new FileOutputStream(DLTempFile);

byte buf[] = new byte[PER_READ];

int readLength = 0;

while (readLength != -1 && !stop) {

if (pause) {

try {

Thread.sleep(1000);

} catch (InterruptedException e) {

e.printStackTrace();

}

continue;

}

readLength = is.read(buf);

if (readLength > 0) {

try {

out.write(buf, 0, readLength);

totalKbRead += readLength;

} catch (Exception e) {

Log.e(TAG, e.toString());

}

}

dealWithBufferData();

}

if (totalKbRead == mediaLength) {

downloadOver = true;

上一页  1 2 3 4 5  下一页

Tags:Android 流媒体 播放器

编辑录入:coldstar [复制链接] [打 印]
赞助商链接