How to play a video from the gallery in another activity? Android

1

I'm having problems when I try to run a video, which I choose in my gallery, in my app (simple).

Follow what I've done so far. If anyone can help me ..

MainActivity:

public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity); 

    play = (Button) findViewById(R.id.play); 

    play.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View v) {
            Intent GaleryIntent = new Intent(Intent.ACTION_PICK, android.provider.MediaStore.Video.Media.EXTERNAL_CONTENT_URI);
            startActivityForResult(GaleryIntent, RESULT_LOAD_IMAGE);
        }
    });
}

@Override 
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
    super.onActivityResult(requestCode, resultCode, data);
    if (requestCode == RESULT_LOAD_IMAGE && resultCode == RESULT_OK && null != data) {
       Uri SelectedImage = data.getData();
       Intent intent = new Intent(this, Video.class);
       intent.putExtra("imagemUri", SelectedImage);
       startActivity(intent);
    }
}

VideoActivity:

protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_main);

    video = (VideoView) findViewById(R.id.video_frame);

    Intent intent = getIntent();
    Uri uri = intent.getParcelableExtra("imagemUri");

    video.setVideoURI(uri);
    video.start();
}

My XML is a button on main, and a VideoView on VideoActivity .

log

10-19 22:04:51.347: E/AndroidRuntime(926): FATAL EXCEPTION: main
10-19 22:04:51.347: E/AndroidRuntime(926): java.lang.SecurityException:    Permission Denial: starting Intent { act=android.intent.action.PICK   dat=content://media/external/video/media   cmp=com.android.music/.VideoBrowserActivity } from ProcessRecord{407b58d0   926:com.example.bancoimagem/10034} (pid=926, uid=10034) requires null
10-19 22:04:51.347: E/AndroidRuntime(926):  at android.os.Parcel.readException(Parcel.java:1322)
10-19 22:04:51.347: E/AndroidRuntime(926):  at android.os.Parcel.readException(Parcel.java:1276)
10-19 22:04:51.347: E/AndroidRuntime(926):  at android.app.ActivityManagerProxy.startActivity(ActivityManagerNative.java:1351)
10-19 22:04:51.347: E/AndroidRuntime(926):  at android.app.Instrumentation.execStartActivity(Instrumentation.java:1374)
10-19 22:04:51.347: E/AndroidRuntime(926):  at android.app.Activity.startActivityForResult(Activity.java:2827)
10-19 22:04:51.347: E/AndroidRuntime(926):  at com.example.bancoimagem.MainActivity$1.onClick(MainActivity.java:35)
10-19 22:04:51.347: E/AndroidRuntime(926):  at android.view.View.performClick(View.java:2485)
10-19 22:04:51.347: E/AndroidRuntime(926):  at android.view.View$PerformClick.run(View.java:9080)
10-19 22:04:51.347: E/AndroidRuntime(926):  at   android.os.Handler.handleCallback(Handler.java:587)
10-19 22:04:51.347: E/AndroidRuntime(926):  at android.os.Handler.dispatchMessage(Handler.java:92)
10-19 22:04:51.347: E/AndroidRuntime(926):  at android.os.Looper.loop(Looper.java:123)
10-19 22:04:51.347: E/AndroidRuntime(926):  at android.app.ActivityThread.main(ActivityThread.java:3683)
10-19 22:04:51.347: E/AndroidRuntime(926):  at java.lang.reflect.Method.invokeNative(Native Method)
10-19 22:04:51.347: E/AndroidRuntime(926):  at java.lang.reflect.Method.invoke(Method.java:507)
10-19 22:04:51.347: E/AndroidRuntime(926):  at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:839)
10-19 22:04:51.347: E/AndroidRuntime(926):  at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:597)
10-19 22:04:51.347: E/AndroidRuntime(926):  at dalvik.system.NativeStart.main(Native Method)
    
asked by anonymous 19.10.2015 / 21:05

0 answers