如何解决媒体播放器错误(1,-2147483648)

时间:2015-01-13 05:31:08

标签: android youtube android-videoview

我想在我的android视频中播放youtube视频,当我在nexus 4.4设备中运行应用程序时,我得到" 无法播放此视频错误&# 34;而且我得到媒体播放器错误,过去两天我尝试但仍然没有成功。这是我的课堂活动代码 我的要求是在视频中播放视频,而不是在youtube播放器中播放视频,所以请仅为视频导航我

public class MainActivity extends Activity {
    private VideoView videoView;
    private MediaController mController;
    private Uri uriYouTube;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);

        videoView = (VideoView) findViewById(R.id.videoView1);
        mController = new MediaController(this);

        videoView.setMediaController(mController);
        videoView.requestFocus();


        if (savedInstanceState != null) {
            int loc = savedInstanceState.getInt("Loc");
            Log.i("Loaction: ", loc + "");
            uriYouTube = Uri.parse(savedInstanceState.getString("url"));
            videoView.setVideoURI(uriYouTube);
            videoView.seekTo(loc);


            videoView.setOnPreparedListener(new OnPreparedListener() {
                @Override
                public void onPrepared(MediaPlayer mp) {
                    Log.v("onPrepared", "ok");
                    mp.start();
                }
            });
        } else {
            RTSPUrlTask truitonTask = new RTSPUrlTask();
            truitonTask.execute("http://www.youtube.com/watch?v=2zNSgSzhBfM");
        }

    }

    void startPlaying(String url) {
        uriYouTube = Uri.parse(url);
        videoView.setVideoURI(uriYouTube);
        videoView.start();
    }

    @Override
    protected void onSaveInstanceState(Bundle outState) {
        super.onSaveInstanceState(outState);
        outState.putInt("Loc", videoView.getCurrentPosition());
        outState.putString("url", uriYouTube.toString());
    }

    @Override
    public boolean onCreateOptionsMenu(Menu menu) {
        getMenuInflater().inflate(R.menu.main, menu);
        return true;
    }

    private class RTSPUrlTask extends AsyncTask<String, Void, String> {
        @Override
        protected String doInBackground(String... urls) {
            String response = getRTSPVideoUrl(urls[0]);
            return response;
        }

        @Override
        protected void onPostExecute(String result) {
            startPlaying(result);
        }

        public String getRTSPVideoUrl(String urlYoutube) {
            try {
                String gdy = "http://gdata.youtube.com/feeds/api/videos/";
                DocumentBuilder dBuilder = DocumentBuilderFactory.newInstance().newDocumentBuilder();
                String id = extractYoutubeId(urlYoutube);
                URL url = new URL(gdy + id);
                HttpURLConnection connection = (HttpURLConnection) url.openConnection();
                Document doc = dBuilder.parse(connection.getInputStream());
                Element el = doc.getDocumentElement();
                NodeList list = el.getElementsByTagName("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) {
                return urlYoutube;
            }
        }

        public String extractYoutubeId(String url) throws MalformedURLException {
            String query = new URL(url).getQuery();
            String[] param = query.split("&");
            String id = null;
            for (String row : param) {
                String[] param1 = row.split("=");
                if (param1[0].equals("v")) {
                    id = param1[1];
                }
            }
            return id;
        }
    }

这是我的logcat错误

01-14 10:41:26.844: D/libEGL(2643): loaded /system/lib/egl/libEGL_tegra.so
01-14 10:41:26.914: D/libEGL(2643): loaded /system/lib/egl/libGLESv1_CM_tegra.so
01-14 10:41:26.974: D/libEGL(2643): loaded /system/lib/egl/libGLESv2_tegra.so
01-14 10:41:27.024: D/OpenGLRenderer(2643): Enabling debug mode 0
01-14 10:41:27.204: D/dalvikvm(2643): GC_FOR_ALLOC freed 225K, 4% free 7886K/8152K, paused 27ms, total 27ms
01-14 10:41:27.634: D/MediaPlayer(2643): Couldn't open file on client side, trying server side
01-14 10:41:27.684: W/MediaPlayer(2643): info/warning (701, 0)
01-14 10:42:40.964: E/MediaPlayer(2643): error (1, -2147483648)
01-14 10:42:40.964: E/MediaPlayer(2643): Error (1,-2147483648)
01-14 10:42:40.964: D/VideoView(2643): Error: 1,-2147483648

我真的不知道我能为这个问题做些什么,我是android新手所以请帮我解决这个问题

0 个答案:

没有答案