我现在用文字和图片制作了一个随机页面,我想为它添加mp3文件。当我单击fab按钮时,会出现文本和图像,但是当我添加像我的代码这样的mp3文件时,它会出错并且我的应用程序会停止。
有没有办法在shufflefacts中添加原始文件?
这是我的facts.java代码:
public class Facts {
private int ivImage;
private String mFact;
private int videoView;
public Facts(int ivImage, int videoView, String mFact) {
this.ivImage = ivImage;
this.videoView = videoView;
this.mFact = mFact;
}
public int getivImage() {
return ivImage;
}
public int getvideoView() {
return videoView;
}
public String getmFact() {
return mFact;
}
public String videoView() {
return null;
}
}
这是我的random.class:
Toolbar mToolbar;
RecyclerView mRecyclerView;
ImageView mFlower;
TextView mDescription;
VideoView videoView;
private FloatingActionButton fab;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_detail);
mToolbar = findViewById(R.id.toolbar);
setSupportActionBar(mToolbar);
ActionBar actionBar= getSupportActionBar();
actionBar.setDisplayHomeAsUpEnabled(true);
mToolbar = findViewById(R.id.toolbar);
videoView = findViewById(R.id.videoView);
mToolbar.setTitle(getResources().getString(R.string.cv));
mRecyclerView = findViewById(R.id.recyclerview);
mFlower = findViewById(R.id.ivImage);
mDescription = findViewById(R.id.tvDescription);
fab = (FloatingActionButton) findViewById(R.id.fab);
fab.setImageResource(R.drawable.vbn);
showRandomFact();
fab.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
showRandomFact();
}
});
}
private void showRandomFact() {
shuffleFacts();
mFlower.setImageResource(factArray[0].getivImage());
videoView.setVideoPath(factArray[0].videoView());
mDescription.setText(factArray[0].getmFact());
}
Facts f01 = new Facts(R.drawable.a, R.raw.b,"hjgbfvjhsdbfvskhbsdıkfvsdkb");
Facts f02 = new Facts(R.drawable.aa, R.raw.b,"hjgbfvjhsdbfvskhbsdıkfvsdkb");
Facts f03 = new Facts(R.drawable.aas, R.raw.b,"hjgbfvjhsdbfvskhbsdıkfvsdkb");
Facts[] factArray = new Facts[] {
f01,f02,f03
};
public boolean shuffleFacts(){
Collections.shuffle(Arrays.asList(factArray));
return true;
}
}