programing

VideoView를 사용한 원활한 비디오 루프

nasanasas 2020. 10. 11. 10:44
반응형

VideoView를 사용한 원활한 비디오 루프


비디오를 원시 리소스로 가져 와서 비디오를 시작하고 반복하는 다음 코드가 있지만 클립의 끝 부분에 와서 클립을 다시 시작할 때 비디오가 원활하게 반복되어야합니다. 나는 정말 내 앱에서 가질 수없는 순간적으로 깜박입니다.

public class Example extends Activity {
    VideoView vv;
    /** Called when the activity is first created. */
    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.main);

        vv = (VideoView)findViewById(R.id.VideoView01);

        //Video Loop
        vv.setOnCompletionListener(new MediaPlayer.OnCompletionListener() {
            public void onCompletion(MediaPlayer mp) {
                vv.start(); //need to make transition seamless.
            }
        });

        Uri uri = Uri.parse("android.resource://com.example/"
                + R.raw.video);

        vv.setVideoURI(uri);
        vv.requestFocus();    
        vv.start();
    }
}

클립은 길이가 22 초에 불과하지만 매끄럽게 제작되어 지연없이 작업 할 수 있습니다.


이것을 시도하면 100 % 작동합니다


videoView.setOnPreparedListener(new OnPreparedListener() {
    @Override
    public void onPrepared(MediaPlayer mp) {
        mp.setLooping(true);
    }
});

일시 중지는 기본 MediaPlayer이 버퍼를 새로 고치는 것입니다. 걸리는 시간은 여러 요인에 따라 달라지며, 그 중 많은 요인이 제어 할 수 없습니다 (예 : CPU 속도, 온보드 플래시 스토리지 속도).

제어 할 수있는 한 가지는 리소스에서 파일 시스템으로 비디오를 가져 오는 것입니다. 리소스는 ZIP 파일 인 APK에 저장되므로이 방법으로 동영상을 추출하는 데 시간이 더 걸릴 수 있습니다.

VideoViewa SurfaceView사용하지 않고 두 개 MediaPlayers를 번갈아 가며 사용해야 할 수 있습니다. 하나는 재생 중이고 다음은 준비 중이므로 하나의 재생이 끝나면 새 플레이어로 전환 할 수 있습니다. 나는 이것을 시도하지 않았으므로 결과가 무엇인지 모르겠습니다. 그러나이 기술은 한 클립에서 다른 클립으로 전환하기 위해 오디오 재생에 자주 사용된다는 것을 알고 있습니다.


이것이 몇 년 후 도움이되는지 확실하지 않지만

vv.start();
vv.setOnCompletionListener ( new MediaPlayer.OnCompletionListener() {

 @Override 
  public void onCompletion(MediaPlayer mediaPlayer) {   
    vv.start();
  }
});

원활한 루프가 있습니다.


조금 늦었지만 다음을 사용할 수없는 이유는 무엇입니까?

MediaPlayer.setLooping(true);

Answer to this is to remove the audio from the video and convert that to a .ogg file which can be looped seamlessly and then use the video without audio to loop round and this works.


Here is answer friends, you must use vv.resume in setOnCompletionListener class

[https://stackoverflow.com/a/27606389/3414469][1]

참고URL : https://stackoverflow.com/questions/4746075/seamless-video-loop-with-videoview

반응형