1

i need help, i have a VideoView and three button under this Videoview, there is a default URL that is set to the Videoview, what i want to achieve is when the user clicks button A, this should change the Videoview to the url which is set to the button the user clicks, the same goes for button B and C, each button clicked should change the view to the url attach to the button click. Presently with the approach am using freezes the current Videoview that is playing and it hangs there. Then I get an error saying below but it doesn't crash the app, it just hangs the Videoview currently showing

MediaPlayer(13338): Error (1,-2147483648) VideoView(13338): Error: 1,-2147483648
this is what am trying:-

 vid = (VideoView) findViewById(R.id.videoview);
 ImageView btnA = (ImageView) findViewById(R.id.low);
 ImageView btnB = (ImageView) findViewById(R.id.high);
 ImageView btnC = (ImageView) findViewById(R.id.audio);

 vid.setVideoPath(--default URL Here---); 


        MediaController mediaController = new MediaController(this);
        mediaController.setAnchorView(vid);
        vid.setMediaController(mediaController);
        vid.requestFocus();
        vid.start();

        videoBuffering = new ProgressDialog(this);
        videoBuffering.setMessage("Loading video data....");
        videoBuffering.setIcon(R.drawable.ic_launcher);
        videoBuffering.setTitle(R.string.app_name);
        videoBuffering.setProgressStyle(ProgressDialog.STYLE_SPINNER);
        videoBuffering.show();

        vid.setOnErrorListener(new OnErrorListener () {
            @Override
            public boolean onError(MediaPlayer mp, int what, int extra) {
                Log.e(TAG, "Error playing video");

                return true;
            }
        });

        vid.setOnPreparedListener(new OnPreparedListener(){

            @Override
            public void onPrepared(MediaPlayer mp) {
                videoBuffering.dismiss();

            }

        });


    btnA.setOnClickListener(new OnClickListener(){

        @Override
        public void onClick(View arg0) {
            if (vid.isPlaying())
            {
                vid.suspend();
                vid.setVideoPath("URL 1");
                vid.start();
            }
            else{
                vid.setVideoPath("URL 1");
                vid.start();
            }
        }

    });

    btnB.setOnClickListener(new OnClickListener(){

        @Override
        public void onClick(View arg0) {
            if (vid.isPlaying())
            {
                vid.suspend();
                vid.setVideoPath("URL 2");
                vid.start();
            }
            else{
                vid.setVideoPath("URL 2");
                vid.start();
            }
        }

    });

    btnC.setOnClickListener(new OnClickListener(){

        @Override
        public void onClick(View arg0) {
            if (vid.isPlaying())
            {
                vid.suspend();
                vid.setVideoPath("URL 3");
                vid.start();
            }
            else{
                vid.setVideoPath("URL 3");
                vid.start();
            }
        }

    });
blessed
  • 127
  • 1
  • 2
  • 11
  • Call `vid.reset()` inside the `setOnClickListeners` of the btnA, btnB and btnC ? – g00dy Aug 08 '13 at 12:22
  • @goody do you mean i should use vid.reset() in place of vid.suspend() – blessed Aug 08 '13 at 12:27
  • I think it hangs because of that yes, no need to suspend it, because you need to load a new url. – g00dy Aug 08 '13 at 12:31
  • @goody it didn't work, when i change to vid.reset() it gives an error which says The method reset() is undefined for the type VideoView – blessed Aug 08 '13 at 12:37
  • Oops :) Thats for the MediaPlayer, try with `vid.stopPlayback();` for instance. – g00dy Aug 08 '13 at 12:39
  • ok, thank you so much for your response so far am grateful, i have been stuck here – blessed Aug 08 '13 at 12:41
  • @goody still didnt work, the video hangs when i click another button, and it shows an error in logcat saying error playing video – blessed Aug 08 '13 at 12:48
  • @goody please what else can i do, or what other approach can you recommend, please help i have been here for days – blessed Aug 08 '13 at 12:53
  • You can try it with `this.finish();` wherever you need to cancel the `MediaController`. This is one way of doing this. Else you can put the code for start and cancel in separate functions. – g00dy Aug 08 '13 at 13:08
  • @googy, still not working – blessed Aug 09 '13 at 09:58
  • This is something outside of my understanding. I would recommend using a library designed just for that, later I will search for such a thing. – g00dy Aug 09 '13 at 09:59

0 Answers0