Tuesday, 4 December 2018

mp4 in VideoView

The original format I had for my video file made it not work for any device, so I ran it through ffmpeg to convert it to a type which would be more compatible. Now, it runs on most devices, but there are still a few that give the error "Cannot play this file"

The command i used to convert it was:

ffmpeg -i <INPUT_VIDEO> -c:v libx264 -profile:v baseline -c:a aac -ar 44100 -ac 2 -b:a 128k -movflags faststart output.mp4

Are there better conversion parameters I could use to make it universally work with all devices? ( I know that 480x360 h264 works for all devices, but I do not want to give up video quality)

Code that works on certain devices:

public class SplashActivity extends AppCompatActivity {

    VideoView videoView;

    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.splash_screen);
        videoView = (VideoView) findViewById(R.id.video_view);

        Uri video = Uri.parse("android.resource://" + getPackageName() + "/" + R.raw.splashv4);
        videoView.setVideoURI(video);

        videoView.setOnCompletionListener(new MediaPlayer.OnCompletionListener() {
            public void onCompletion(MediaPlayer mp) {
                startNextActivity();
            }
        });

        videoView.start();
    }

    private void startNextActivity() {
        if (isFinishing())
            return;
        startActivity(new Intent(this, LoginActivity.class));
        finish();
    }
}



from mp4 in VideoView

No comments:

Post a Comment