how to resolve media player error(1,-2147483648)

为君一笑 提交于 2019-12-11 02:19:44

问题


i am trying to play youtube video in my android videoview , when i run the application in nexus 4.4 device, i am getting "can't play this video error" and also i am getting media player error, past two days i am trying but still not success.this is my class activity code my requirement is to play video in videoview not in youtube player so please guide me only for videoview

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

this is my logcat error

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

really i don't know what can i do for this issues, i am new to android so please help me to solve this issues

来源:https://stackoverflow.com/questions/27915452/how-to-resolve-media-player-error1-2147483648

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!