从HTTP服务器的Andr​​oid视频播放 [英] Playing video from http server in android

查看:166
本文介绍了从HTTP服务器的Andr​​oid视频播放的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在我加载的所有视频的从服务器上的特定文件夹列表视图。现在我所要做的是通过点击列表项应的视频观看播放的视频。一切似乎工作完美,但只有我面临的问题是,当我在它是不是在玩的视频列表视图项点击。

I have a list-view in which i am loading all video's from server's particular folder. now what i am trying to do is by clicking a list item it should play that video in video view. Everything seems to work perfect, but only problem i am facing is when i click on list-view item it is not playing that video.

PS。我得到以下日志错误日志,但我的应用程序是不是很遗憾停止,我的显示器是继续显示我的视频加载中,我在AsyncTask的设置,但是当我在日志猫检查我看到这个错误进度条。

PS. I am getting following log in error log, but my application is not stopping unfortunately, my display is keep showing me that video is loading in progress bar which i set in Asynctask, but when i checked in log cat i saw this error.

我当然在谷歌搜索以及SO,但我并没有得到满意的结果。

Of course i have searched in google as well as SO but i did not got satisfactory result.

Folowwing是我的日志猫的信息。

Folowwing is my log cat message.

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)

和以下是我的code。

And following is my code.

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来的playVideo

and this is my Asynctask to playvideo

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方法。

and following is my playVideo method.

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();
    }

我也试图创造doInBackground方法新线程,并还准备卸下线程,但这种技巧并不为我工作。

I also tried to creating new thread in doInbackground method and by removing thread also, but this tricks does not worked for me.

还一件事,它显示在线路225错误是 MC =新的MediaController(本);

also one thing that it showing error on line 225 that is mc = new MediaController(this);

推荐答案

您可以删除您的AsyncTask,并直接播放视频使用下面code,

You can remove your AsyncTask and play your video directly using below code,

String url1 = null; 
Object o1 = myList.get(position); 
url1 = o1.toString().replace(" ", "%20").trim(); 
playVideo(url1);

这篇关于从HTTP服务器的Andr​​oid视频播放的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆