目前,我正在像這樣設置視頻視圖的視頻路徑;在VideoView中更改視頻的路徑
"android.resource://" + getPackageName() + "/" + R.raw.videoName
但是我希望能夠通過從R.raw中的文件生成的數組中選擇視頻文件的名稱來更改videoName。
什麼是最好的方法來做到這一點?
目前,我正在像這樣設置視頻視圖的視頻路徑;在VideoView中更改視頻的路徑
"android.resource://" + getPackageName() + "/" + R.raw.videoName
但是我希望能夠通過從R.raw中的文件生成的數組中選擇視頻文件的名稱來更改videoName。
什麼是最好的方法來做到這一點?
我的一個解決方法是通過設置這樣的路徑,其中路徑是一個String變量,取自array.get(position)。
vidPath = "android.resource://" + getPackageName() + "/" + "/raw/" + path;
假設您有2個視頻。
int videoArray[]={R.raw.videoName1,R.raw.videoName2};
public void onCreate(Bundle savedInstanceState)
{
button1 = ((Button)this.findViewById(R.id.button1));
button2 = ((Button)this.findViewById(R.id.button2));
button1.setOnClickListener(this);
button2.setOnClickListener(this);
VideoView vv = (VideoView) this.findViewById(R.id.surface);
}
public void onClick(View v) {
switch(v.getId()){
case R.id.button1:
String uriPath = "android.resource://"+ getPackageName() + "/raw/"+videoArray[0];
Uri uri = Uri.parse(uriPath);
vv.setVideoURI(uri);
vv.start();
break;
case R.id.button2:
String uriPath = "android.resource://"+ getPackageName() + "/raw/"+videoArray[1];
Uri uri = Uri.parse(uriPath);
vv.setVideoURI(uri);
vv.start();
break;
}
這是根據點擊按鈕改變視頻? – Huhtamaki
是的。你可以做更多像在回收站查看。 –
爲數組添加切換條件。因爲我不認爲你可以在for循環中使用這個R.raw。 –