我想在单击按钮时在同一个视频视图中播放多个视频,在其他布局示例中的视频视图中播放在线视频:
单击任何按钮后,“布局 1”中有三个按钮转到“布局 2”“布局 2”中有一个 VideoView 每个人都操作单击按钮是在 VideoView 中更改字符串值“VideoURl”
问题是:当您单击布局 1 中的任何按钮时,如何更改布局 2 中字符串变量的值?!!] 1
http://i.stack.imgur.com/ytQiE.jpg
public class MainActivity extends Activity{
Button button1;
public void onCreate(Bundle savedInstanceState)
{
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
addListenerOnButton();
}
public void addListenerOnButton() {
final Context context = this;
button1 = (Button) findViewById(R.id.button1);
button1.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View arg0) {
Intent i = new Intent(context, Main2Activity.class);
i.putExtra("VidURL1", "http://img580.imageshack.us/img580/416/4dojlrwiknaexgxaiyqfbz.mp4");
startActivity(i);
}
});
}
}
守则活动 2:
public class Main2Activity extends Activity {
private ProgressDialog pDialog;
VideoView videoview;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
videoview = (VideoView) findViewById(R.id.VideoView);
new StreamVideo().execute();
}
private class StreamVideo extends AsyncTask {
@Override
protected void onPreExecute() {
super.onPreExecute();
pDialog = new ProgressDialog(Main2Activity.this);
pDialog.setTitle("Android Video Streaming Tutorial");
pDialog.setMessage("Buffering...");
pDialog.setIndeterminate(false);
pDialog.show();
}
@Override
protected Void doInBackground(Void... params) {
// TODO Auto-generated method stub
return null;
}
@Override
protected void onPostExecute(Void args) {
try {
// Start the MediaController
MediaController mediacontroller = new MediaController(
Main2Activity.this);
mediacontroller.setAnchorView(videoview);
// Get the URL from String VideoURL
Uri video = Uri.parse(VideoURL);
videoview.setMediaController(mediacontroller);
videoview.setVideoURI(video);
videoview.requestFocus();
videoview.setOnPreparedListener(new OnPreparedListener() {
// Close the progress bar and play the video
public void onPrepared(MediaPlayer mp) {
pDialog.dismiss();
videoview.start();
}
});
} catch (Exception e) {
pDialog.dismiss();
Log.e("Error", e.getMessage());
e.printStackTrace();
}
}
}
@Override
public boolean onCreateOptionsMenu(Menu menu) {
getMenuInflater().inflate(R.menu.main, menu);
return true;
}
}