在客户端便无法打开文件 [英] Could't open file on client side

查看:146
本文介绍了在客户端便无法打开文件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想在Android视频以播放视频。但是当我运行code它会打开一个媒体播放器,但不播放视频,并给我一个错误信息和日志猫显示头被埋打开该文件,在客户端尝试服务器端。这里是我的code:

 公共类ExercisesActivity延伸活动{VideoView videoView;
串videoUrl;
公共布尔flage = TRUE;
@覆盖
保护无效的onCreate(捆绑savedInstanceState){
    super.onCreate(savedInstanceState);
    的setContentView(R.layout.activity_exercises);     videoView =(VideoView)findViewById(R.id.videoView);
    新performBackgroundTask(ExercisesActivity.this).execute();
}公共无效的onPause()
{
super.onPause();
videoView.stopPlayback();
}私有类performBackgroundTask扩展的AsyncTask<虚空,虚空,虚空>
{
                私人ProgressDialog对话框;                    公共performBackgroundTask(ExercisesActivity上下文)
                    {
                        对话=新ProgressDialog(背景);
                    }            在preExecute保护无效()
               {                this.Dialog.setMessage(加载视频...);
                this.Dialog.show();              }
             保护无效doInBackground(无效... PARAMS)
             {
                 尝试
                 {
                     字符串URL =htt​​p://www.youtube.com/watch?v=m5_AKjDdqaU;
                     videoUrl = getUrlVideoRTSP(URL);
                     Log.e(视频网址为播放=========>>>>>中,videoUrl);
                 }
                 赶上(例外五)
                 {
                     Log.e(登录肥皂在调用异常,e.toString());
                 }
                          返回null;
             }
            保护无效onPostExecute(虚空未使用)
           {
                如果(!fl​​age){                    如果(Dialog.isShowing())
                    {
                        Dialog.dismiss();
                    }
                }
                其他
                {
                    videoView.setVideoURI(Uri.parse(videoUrl));
        MC的MediaController =新的MediaController(ExercisesActivity.this);
                    videoView.setMediaController(MC);
                    videoView.requestFocus();
                    videoView.start();
                    mc.show();
                }                    如果(Dialog.isShowing())
                    {
                        Dialog.dismiss();
                    }
                }            }
公共静态字符串getUrlVideoRTSP(字符串urlYoutube)
    {
    尝试
    {
        字符串GDY =htt​​p://gdata.youtube.com/feeds/api/videos/;
        的DocumentBuilder的DocumentBuilder
       = DocumentBuilderFactory.newInstance()newDocumentBuilder();
        字符串ID = extractYoutubeId(urlYoutube);
        网址URL =新的URL(GDY + ID);
        HttpURLConnection的连接=(HttpURLConnection类)url.openConnection();
        文档的文档= documentBuilder.parse(connection.getInputStream());
        元件EL = doc.getDocumentElement();
        节点列表清单= el.getElementsByTagName(媒体:内容); ///媒体:内容
        字符串指针= urlYoutube;
        的for(int i = 0; I< list.getLength();我++)
        {
            节点node = list.item(ⅰ);
            如果(节点!= NULL)
            {
                的NamedNodeMap nodeMap = node.getAttributes();
                HashMap的<字符串,字符串>地图=新的HashMap<字符串,字符串>();
                对于(INT J = 0; J< nodeMap.getLength(); J ++)
                {
                    ATTR ATT =(attr)使用nodeMap.item(J);
                    maps.put(att.getName(),att.getValue());
                }
                如果(maps.containsKey(YT:格式))
                {
                    串f = maps.get(YT:格式);
                    如果(maps.containsKey(URL))
                    {
                        光标= maps.get(URL);
                    }
                    如果(f.equals(1))
                        返回游标;
                }
            }
        }
        返回游标;
    }
    赶上(异常前)
    {
        Log.e(获取网址视频RTSP异常======>>中,ex.toString());
    }
    返回urlYoutube;}受保护的静态字符串extractYoutubeId(字符串URL)抛出MalformedURLException的{字符串ID = NULL;
    尝试
    {
        查询字符串=新的URL(网址).getQuery();
        如果(查询!= NULL)
        {
            的String []参数= query.split(与&);
            对于(字符串行:参数)
            {
                串[]的param1 = row.split(=);
                如果(参数1 [0] .equals(V))
                {
                    ID =参数1 [1];
                }
            }
        }
        其他
        {
            如果(url.contains(嵌入))
            {
                ID = url.substring(url.lastIndexOf(/)+ 1);
            }
        }
    }
    赶上(异常前)
    {
        Log.e(异常,ex.toString());
    }
    返回ID;
    }}

日志猫所示:

  20 01-07:36:40.388:E /视频地址用于播放=========>>>>>(378):
RTSP://r4---sn-4g57kue6.c.youtube.com/CiILENy73wIaGQmlqd0wKsCfmxMYDSANFEgGUgZ2aWRlb3MM/0/0/0/video.3gp
01-07 20:36:40.398:D / MediaPlayer的(378):可以在客户端无法打开文件,试图
服务器端


解决方案

的RTSP链接不工作由YouTube API 2.0版提供的任何数据。而且我不认为它会是固定的。
的https://$c$c.google.com / p / gdata的-问题/问题/细节?ID = 4858

I am trying to play a video in Android video view. but when i run the code it opens a media player but don't play the video and give me an error message and log cat shows "could't open the file at client side trying server side." here is my code:

public class ExercisesActivity extends Activity {

VideoView videoView;
String videoUrl;
public boolean flage = true;
@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_exercises);

     videoView = (VideoView)findViewById(R.id.videoView);
    new performBackgroundTask(ExercisesActivity.this).execute();
}

public void onPause ()
{
super.onPause();
videoView.stopPlayback();
}

private class performBackgroundTask extends AsyncTask < Void, Void, Void >
{


                private ProgressDialog Dialog;

                    public performBackgroundTask(ExercisesActivity context)
                    {
                        Dialog = new ProgressDialog(context);
                    }                   



            protected void onPreExecute()
               {

                this.Dialog.setMessage("Loading Video...");
                this.Dialog.show();

              }


             protected Void doInBackground(Void... params)
             {
                 try
                 {
                     String url = "http://www.youtube.com/watch?v=m5_AKjDdqaU";
                     videoUrl = getUrlVideoRTSP(url);
                     Log.e("Video url for playing=========>>>>>", videoUrl);
                 }
                 catch (Exception e)
                 {
                     Log.e("Login Soap Calling in Exception", e.toString());
                 }
                          return null;
             }


            protected void onPostExecute(Void unused)
           {


                if(!flage){

                    if(Dialog.isShowing())
                    {
                        Dialog.dismiss();
                    }


                }
                else
                {
                    videoView.setVideoURI(Uri.parse(videoUrl));
        MediaController mc = new  MediaController(ExercisesActivity.this);
                    videoView.setMediaController(mc);
                    videoView.requestFocus();
                    videoView.start();          
                    mc.show();
                }

                    if(Dialog.isShowing())
                    {
                        Dialog.dismiss();
                    }
                }

            }


public static String getUrlVideoRTSP(String urlYoutube)
    {
    try
    {
        String gdy = "http://gdata.youtube.com/feeds/api/videos/";
        DocumentBuilder  documentBuilder
       =DocumentBuilderFactory.newInstance().newDocumentBuilder();   
        String id = extractYoutubeId(urlYoutube);
        URL url = new URL(gdy + id);
        HttpURLConnection connection = (HttpURLConnection) url.openConnection();
        Document doc = documentBuilder.parse(connection.getInputStream());
        Element el = doc.getDocumentElement();
        NodeList list = el.getElementsByTagName("media:content");///media:content
        String cursor = urlYoutube;
        for (int i = 0; i < list.getLength(); i++)
        {
            Node node = list.item(i);
            if (node != null)
            {
                NamedNodeMap nodeMap = node.getAttributes();
                HashMap<String, String> maps = new HashMap<String, String>();
                for (int j = 0; j < nodeMap.getLength(); j++)
                {
                    Attr att = (Attr) nodeMap.item(j);
                    maps.put(att.getName(), att.getValue());
                }
                if (maps.containsKey("yt:format"))
                {
                    String f = maps.get("yt:format");
                    if (maps.containsKey("url"))
                    {
                        cursor = maps.get("url");
                    }
                    if (f.equals("1"))
                        return cursor;
                }
            }
        }
        return cursor;
    }
    catch (Exception ex)
    {
        Log.e("Get Url Video RTSP Exception======>>", ex.toString());
    }
    return urlYoutube;

}

protected static String extractYoutubeId(String url) throws MalformedURLException      

{        String id = null;
    try
    {
        String query = new URL(url).getQuery();
        if (query != null)
        {
            String[] param = query.split("&");
            for (String row : param)
            {
                String[] param1 = row.split("=");
                if (param1[0].equals("v"))
                {
                    id = param1[1];
                }
            }
        }
        else
        {
            if (url.contains("embed"))
            {
                id = url.substring(url.lastIndexOf("/") + 1);
            }
        }
    }
    catch (Exception ex)
    {
        Log.e("Exception", ex.toString());
    }
    return id;
    }

}

The log cat shows:

01-07 20:36:40.388: E/Video url for playing=========>>>>>(378):
rtsp://r4---sn-4g57kue6.c.youtube.com/CiILENy73wIaGQmlqd0wKsCfmxMYDSANFEgGUgZ2aWRlb3MM

/0/0/0/video.3gp
01-07 20:36:40.398: D/MediaPlayer(378): Couldn't open file on client side, trying
server side

解决方案

The RTSP link is not working for any data provided by Youtube API v 2.0. And I don't think its going to be fixed. https://code.google.com/p/gdata-issues/issues/detail?id=4858

这篇关于在客户端便无法打开文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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