最近准备着手研究下流媒体播放,苦于没有开放的支持rtsp协议的api
望各位大拿予以支持,将会万分感谢!....
如有经验者用其他的方法予以支持,
thank you all the same...
望各位大拿予以支持,将会万分感谢!....
如有经验者用其他的方法予以支持,
thank you all the same...
解决方案 »
- Android下,调用linux的创建设备节点的命令mknod,没有任何反应。节点没有创建成功,但是也无出错信息。请问是怎么回事?
- adb进入数据库命令sqlite3出现 not found
- 关于animation-list图片大小的修改
- 设置壁纸问题
- 新手遇到问题,求教!
- 求mpeg2解码移植到android的方法
- 高手大哥帮帮忙,实在没辙了。
- 求助,menu item过多情况下的显示问题
- android listview 绑定的adapter中,改变button的背景
- 问一个关于MediaPlayer的问题
- 自启动apk,不是开机自启动apk
- cygwin里如何访问window下的JDK呢
http://topic.csdn.net/u/20091126/10/09ba4ba0-90fb-4cc2-9b0b-39112c33342b.html
import java.io.File;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStreamWriter;
import java.net.MalformedURLException;
import java.net.URL;
import java.net.URLConnection;import android.app.Activity;
import android.media.MediaPlayer;
import android.os.Bundle;
import android.os.Handler;
import android.util.Log;
import android.view.View;
import android.view.View.OnClickListener;
import android.webkit.WebView;
import android.widget.Button;public class MainActivity extends Activity {
private WebView webView;
private Button btn;
private MediaPlayer mPlayer;
private boolean downloadOver = false; private boolean wasPlayed = false;
private static final String TAG = "AudioPlayer";
private String current; private static final int MIN_BUFF = 100 * 1024; private int totalKbRead = 0; private Handler handler = new Handler(); private File DLTempFile; private File BUFFTempFile; private final String TEMP_DOWNLOAD_FILE_NAME = "tempMediaData"; private final String TEMP_BUFF_FILE_NAME = "tempBufferData"; private final String FILE_POSTFIX = ".dat"; private final int PER_READ = 1024; private boolean pause; private boolean stop; private final int UNKNOWN_LENGTH = -1; private final String MUSIC_URL = "http://www.6e.cn/photo/2008/11/28/20081129105638220.mp3"; public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main); webView = (WebView) findViewById(R.id.swfWebv);
webView.getSettings().setPluginsEnabled(true); mPlayer = new MediaPlayer(); btn = (Button) findViewById(R.id.Button01);
btn.setOnClickListener(new OnClickListener() {
public void onClick(View v) { PlayMusicOnline(MUSIC_URL, 0, UNKNOWN_LENGTH); }
});
}
private void PlayMusicOnline(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; } /*创建临时文件*/
DLTempFile = new File("/sdcard/winter1.mp3");
/*创建文件输入流*/
out = new FileOutputStream(DLTempFile,true);
/*创建字节数组*/
byte buf[] = new byte[PER_READ]; int readLength = 0;
//
while (readLength != -1 && !stop) { if (pause) { try { Thread.sleep(3000); } catch (InterruptedException e) { e.printStackTrace(); } continue; }
/* 字节长度*/
readLength = is.read(buf);
if (readLength > 0) { try {
/* 向文件追加写入该段字节内容*/
out.write(buf, 0, readLength);
/* 当前字节总长度,包括之前*/
totalKbRead += readLength; } catch (Exception e) {
e.printStackTrace();
} } } if (totalKbRead == mediaLength) { downloadOver = true;// 删除临时文件
//
// if (DLTempFile != null && DLTempFile.exists()) {
//
// DLTempFile.delete();
//
// } } } catch (MalformedURLException e) { Log.e(TAG, e.toString()); } catch (IOException e) { Log.e(TAG, e.toString()); } finally { if (out != null) { try { out.close(); } catch (IOException e) { e.printStackTrace(); } } if (is != null) { try { is.close(); } catch (IOException e) { e.printStackTrace(); } } } }
}
对阿,只是用http去模拟那个rtsp的过程,我做过试验了可以行得通。实际上就是http