如何使用Intent将视频路径传递给另一个活动?

时间:2014-09-14 12:10:56

标签: android

建立一个应用程序,我想在应用程序中自定义我自己的视频播放器,我不想使用默认的Android媒体播放器。 活动1:

 String VideoUri= fileUri.toString();
//            Intent videoIntent = new Intent(getListView().getContext(), VideoPlayerActivity.class);
//           videoIntent.putExtra("VideoPath", VideoUri);
//               startActivity(videoIntent);

活动2:

import android.app.Activity;
import android.app.ProgressDialog;
import android.media.MediaPlayer;
import android.media.MediaPlayer.OnPreparedListener;
import android.net.Uri;
import android.os.Bundle;
import android.util.Log;
import android.widget.MediaController;
import android.widget.VideoView;

public class VideoPlayerActivity extends Activity {

    ProgressDialog myDialog;
    VideoView myvideoview;


    final String VideoUrl=getIntent().getExtras().getString("VideoPath");

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);

        setContentView(R.layout.activity_video_player);

        myvideoview = (VideoView) findViewById(R.id.uservideoView);


        myDialog = new ProgressDialog(VideoPlayerActivity.this);

        myDialog.setTitle("Video Loading");

        myDialog.setMessage("Streaming...");
        myDialog.setIndeterminate(false);
       myDialog.setCancelable(false);

        myDialog.show();

        try {

            MediaController mediacontroller = new MediaController(
                    VideoPlayerActivity.this);
            mediacontroller.setAnchorView(myvideoview);

            Uri video = Uri.parse(VideoUrl);
            myvideoview.setMediaController(mediacontroller);
            myvideoview.setVideoURI(video);

        } catch (Exception e) {
            Log.e("Error", e.getMessage());
            e.printStackTrace();
        }

        videoview.requestFocus();
        videoview.setOnPreparedListener(new OnPreparedListener() {
            public void onPrepared(MediaPlayer mp) {
                myDialog.dismiss();
                myvideoview.start();
            }
        });

    }

}

Image Viewer适用于我使用Picasso API。有没有其他方法可以将Video Uri Pass传递给新的Activity /

1 个答案:

答案 0 :(得分:0)

你可以使用Application Singleton像这样: http://pastebin.com/JPRvAiv7