现在,对于视频我首先下载它然后播放它需要更多的时间…所以有任何机制,我可以直接从远程网址播放视频???
请帮我 …
我迫切需要答案……
提前致谢 ……..
看看我的代码片段::
public voID onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentVIEw(R.layout.notificationvIDeo); mVIDeoVIEw = (VIDeoVIEw) findVIEwByID(R.ID.vIDeo); //pd=ProgressDialog.show(this,"Loading...","Please Wait...",true,false); playVIDeo(); //pd.dismiss(); img_back = (ImageVIEw) findVIEwByID(R.ID.img_back); img_back.setonClickListener(new VIEw.OnClickListener() { public voID onClick(VIEw v) { Intent int_back=new Intent(NotificationsVIDeoActivity.this,MyChannelsActivity.class); startActivity(int_back); finish(); } }); }private voID playVIDeo() { try { path = getIntent().getStringExtra("url"); Log.v(TAG,"path: " + path); if (path == null || path.length() == 0) { Toast.makeText(NotificationsVIDeoActivity.this,"file URL/path is empty",Toast.LENGTH_LONG).show(); } else { // If the path has not changed,just start the media player if (path.equals(current) && mVIDeoVIEw != null) { mVIDeoVIEw.start(); mVIDeoVIEw.requestFocus(); return; } current = path; mVIDeoVIEw.setVIDeoPath(getDataSource(path)); mVIDeoVIEw.start(); mVIDeoVIEw.requestFocus(); } } catch (Exception e) { Log.e(TAG,"error: " + e.getMessage(),e); if (mVIDeoVIEw != null) { mVIDeoVIEw.stopPlayback(); } }}private String getDataSource(String path) throws IOException{ if (!URLUtil.isNetworkUrl(path)) { return path; } else { URL url = new URL(path); URLConnection cn = url.openConnection(); cn.connect(); inputStream stream = cn.getinputStream(); if (stream == null) throw new RuntimeException("stream is null"); file temp = file.createTempfile("mediaplayertmp","mp4"); temp.deleteOnExit(); String tempPath = temp.getabsolutePath(); fileOutputStream out = new fileOutputStream(temp); byte buf[] = new byte[128]; //byte buf[] = new byte[8192]; do { int numread = stream.read(buf); if (numread <= 0) break; out.write(buf,numread); } while (true); try { stream.close(); } catch (IOException ex) { Log.e(TAG,"error: " + ex.getMessage(),ex); } return tempPath; }}解决方法 试试这个 –
String path="http://www.ted.com/talks/download/vIDeo/8584/talk/761";String path1="http://commonsware.com/misc/test2.3gp";Uri uri=Uri.parse(path1);VIDeoVIEw vIDeo=(VIDeoVIEw)findVIEwByID(R.ID.VIDeoVIEw01);vIDeo.setVIDeoURI(uri);vIDeo.start();总结
以上是内存溢出为你收集整理的如何在Android中播放远程网址的实时视频流?全部内容,希望文章能够帮你解决如何在Android中播放远程网址的实时视频流?所遇到的程序开发问题。
如果觉得内存溢出网站内容还不错,欢迎将内存溢出网站推荐给程序员好友。
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)