E / MediaPlayer: error (1, -1010) Error trying to open a SplashActivity with a video

0

Here my code:

public class SplashActivity extends Activity {

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        // Set portrait orientation
        setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_PORTRAIT);
        // Hide title bar
        requestWindowFeature(Window.FEATURE_NO_TITLE);
        try {
            VideoView videoHolder = new VideoView(this);
            setContentView(videoHolder);
            Uri video = Uri.parse("android.resource://" + getPackageName() + "/" + R.raw.x);
            videoHolder.setVideoURI(video);

            videoHolder.setOnCompletionListener(new MediaPlayer.OnCompletionListener() {
                public void onCompletion(MediaPlayer mp) {
                    jump();
                }
            });
            videoHolder.start();
        } catch (Exception ex) {
            jump();
        }
    }

    @Override
    public boolean onTouchEvent(MotionEvent event) {
        jump();
        return true;
    }

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

At the moment I run the application the screen throws me an error that says

  

"Unable to play the video"

However I upload my next activity with no problem after the error message, I did the SplashActivity with a .Gif and it did without problem, the thing is that I want the animations to start have sound, so I try to implement a video with the same content as .Gif

    
asked by David Villegas 20.06.2018 в 22:31
source

1 answer

-1

Regarding the error you mention:

  

"Unable to play the video"

These are mainly the causes why the audio can not be played:

  • The file found in the /raw folder may not actually be a video / audio file, check it is the x file. *.
  • The file was not generated with the codecs supported by android
  

However, I upload my next activity without problem

Load the next activity because when an error occurs you also call the jump() method which performs the intent to open the Activity.

 try {
      ...
      ...
       //Reproduce video.
      ...
      ...
   } catch (Exception ex) {
     jump();
   }
    
answered by 20.06.2018 в 23:04