如何点击按钮在另一个活动中播放视频?

问题描述 投票:0回答:1

我首先做了两个活动我在cardview中有视频列表列表我想在其他活动上播放该视频。我在第二个活动中添加了videoview,我不希望多个视频有多个活动。希望你们明白。

package eras.ppt.ras;

import android.content.Intent;
import android.provider.MediaStore;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.support.v7.widget.CardView;
import android.view.View;

public class FYJCActivity extends AppCompatActivity {

    CardView mycard ;
    private Intent intent;
    private Intent intent1;
    private Intent intent2;
    private Intent intent3;
    private Intent intent4;
    private Intent intent5;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_fyjc);

        mycard = (CardView) findViewById(R.id.physics);
        mycard.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                Intent intent = new Intent(FYJCActivity.this, VideoActivity.class);
                startActivity(intent);
//                finish();
//                onBackPressed();
            }
        });

        mycard = (CardView) findViewById(R.id.cardview);
        mycard.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                Intent intent1 = new Intent(FYJCActivity.this, VideoActivity.class);
                startActivity(intent1);
//                finish();
//                onBackPressed();
            }
        });

        mycard = (CardView) findViewById(R.id.cardview1);
        mycard.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                Intent intent2 = new Intent(FYJCActivity.this, VideoActivity.class);
                startActivity(intent2);
//                finish();
//                onBackPressed();
            }
        });

        mycard = (CardView) findViewById(R.id.cardview2);
        mycard.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                Intent intent3 = new Intent(FYJCActivity.this, VideoActivity.class);
                startActivity(intent3);
//                finish();
//                onBackPressed();
            }
        });

        mycard = (CardView) findViewById(R.id.cardview3);
        mycard.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                Intent intent4 = new Intent(FYJCActivity.this, VideoActivity.class);
                startActivity(intent4);
//                finish();
//                onBackPressed();
            }
        });

        mycard = (CardView) findViewById(R.id.cardview4);
        mycard.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                Intent intent5 = new Intent(FYJCActivity.this, VideoActivity.class);
                startActivity(intent5);
//                finish();
//                onBackPressed();
            }
        });

    }
}

这是我想要播放视频活动视频的代码。我不知道如何播放其他活动的视频,这就是为什么我还没有添加视频链接。

android button android-videoview
1个回答
0
投票

您必须使用putExtra在intent中添加额外信息。对于前者,

 mycard = (CardView) findViewById(R.id.physics);
        mycard.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                Intent intent = new Intent(FYJCActivity.this, VideoActivity.class);
                intent.putExtra("a_Tag","physics");
                startActivity(intent);
            }
        });

在您的VideoActivity中,在onCreate方法中,您必须从intent中提取该信息,如下所示:

String item_selected=getIntent().getStringExtra("a_Tag"); //same tag you used before
//now item_selected is "physics"

您可以根据item_selected的值显示相应的视频

© www.soinside.com 2019 - 2024. All rights reserved.