我想在同一视频中播放很多视频 点击按钮时,在其他布局中以videoview播放在线视频 例如:
“布局1”中有三个按钮 点击任何按钮后转到“布局2” “布局2”中有一个VideoView 每个人的动作点击按钮是在VideoView中更改字符串值“VideoURl”
问题是:如何更改布局2中String变量的值当您单击布局1中的任何按钮时?!!] 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;
}
}
答案 0 :(得分:0)
您可以使用意图
在两个活动之间传递数据Intent intent = new Intent(getBaseContext(), SignoutActivity.class);
intent.putExtra("EXTRA_SESSION_ID", sessionId);
startActivity(intent)
并从activity1获取数据
String Url = getIntent().getExtras().getString("yourKey");