Android VideoView, you need to quickly switch between videos

I am developing a new application and using VideoView to display mpeg clips.

I need to switch between the videos very quickly, however, loading a new clip into VideoView takes about a second and a half of a black screen.

The transition should be smooth, how would you decide to solve this problem?

+4
source share
2 answers

I had a similar problem and resolved using still image conversion (ImageView):

  • create framelayout with imageview over videoview
  • ImageView shows the first frame of the video
  • ImageView is initially visible.
  • start the video, wait for an arbitrary time (for example, 2-300 ms)
  • hide ImageView

to switch two videos: - show image - switch video - hide image

bit hacky but worked for me

+2
source

I had the same problem, but I used mediaplayer , my code is:

Here I use the button to start the action of the switch, before switching, I already uploaded the video and prepare for the switch. When you need it, you just need to stop and release the old mediaplayer and start a new one. The key to seamless switching is sleep() , when the process was asleep, in fact the video is still ongoing, but give the system some time to prepare for the next.

  switch_button = (Button) findViewById(R.id.button_switch); switch_button.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { Button switch_button = (Button) v; VideoPlayer2 = new MediaPlayer(); try { VideoPlayer2.setDataSource("rtsp://" + hostIP + ":1935/vod/Timer.mp4"); VideoPlayer2.prepare(); VideoPlayer2.setAudioStreamType(AudioManager.STREAM_MUSIC); } catch (IOException e) { e.printStackTrace(); } try { Thread.sleep(2000); } catch (InterruptedException e) { e.printStackTrace(); } VideoPlayer.release(); VideoPlayer2.setDisplay(vidHolder); VideoPlayer2.start(); } }); 
+1
source

Source: https://habr.com/ru/post/1401022/


All Articles