我有一个列表视图,我从服务器的特定文件夹加载所有视频.现在我要做的是点击一个列表项,它应该在视频视图中播放该视频.一切似乎都很完美,但我遇到的唯一问题是,当我点击列表视图项目时,它不会播放该视频.
PS.我正在跟踪登录错误日志,但我的应用程序没有停止不幸,我的显示器继续向我显示视频正在加载进度栏我设置在Asynctask,但当我检查日志猫我看到这个错误.
当然我已经在谷歌搜索过以及SO但我没有得到满意的结果.
Folowwing是我的日志猫消息.
02-21 11:08:52.964: W/SurfaceFlinger(101): nothing to do with mask 0x00000000 02-21 11:08:52.974: W/System.err(1992): java.lang.RuntimeException: Can't create handler inside thread that has not called Looper.prepare() 02-21 11:08:52.976: W/System.err(1992): at android.os.Handler.<init>(Handler.java:121) 02-21 11:08:52.976: W/System.err(1992): at android.widget.MediaController$3.<init>(MediaController.java:474) 02-21 11:08:52.977: W/System.err(1992): at android.widget.MediaController.<init>(MediaController.java:474) 02-21 11:08:52.978: W/System.err(1992): at android.widget.MediaController.<init>(MediaController.java:210) 02-21 11:08:52.978: W/System.err(1992): at iqual.fidol_final.ServerFileList.playVideo(ServerFileList.java:225) 02-21 11:08:52.979: W/System.err(1992): at iqual.fidol_final.ServerFileList.access$3(ServerFileList.java:221) 02-21 11:08:52.979: W/System.err(1992): at iqual.fidol_final.ServerFileList$PlayVideo$1.run(ServerFileList.java:181) 02-21 11:08:52.979: W/System.err(1992): at java.lang.Thread.run(Thread.java:856)
以下是我的代码.
mListView.setOnItemClickListener(new OnItemClickListener() { @Override public void onItemClick(AdapterView<?> parent,View view,int position,long id) { String url1 = null; Object o1 = myList.get(position); url1 = o1.toString().replace(" ","%20").trim(); playVideo = (PlayVideo) new PlayVideo(url1).execute(); } });
这是我播放视频的Asynctask
class PlayVideo extends AsyncTask<String,Void,Boolean> { String baseURL; public PlayVideo(String baseURL) { this.baseURL = baseURL; } @Override protected void onPreExecute() { super.onPreExecute(); pDialog = ProgressDialog.show(ServerFileList.this," Buffering...","please wait..",false); pDialog.setCancelable(false); } @Override protected Boolean doInBackground(String... urls) { Thread thread = new Thread(new Runnable() { @Override public void run() { try { playVideo(baseURL); } catch (Exception e) { e.printStackTrace(); } } }); thread.start(); return true; } @Override protected void onPostExecute(Boolean result) { super.onPostExecute(result); } }
以下是我的playVideo方法.
private void playVideo(String baseURL) { Uri myUri = Uri.parse(baseURL); MediaController mc; mc = new MediaController(this); mVideoView.setMediaController(mc); mVideoView.setVideoURI(myUri); System.out.println("====Myuri=====" + myUri); mVideoView.requestFocus(); mVideoView.start(); }