我有一个简单的按钮,我希望通过单击此按钮但没有videoView或webView来播放URL视频(xxx.mp4)。因此,如果我点击按钮,手机将询问我将选择播放视频的内部播放器。
播放视频的按钮:button3
视频链接:http://wisdom.gotdns.com/application/android/res/00/1112PJ12.mp4
cv_1112pj12.java
package com.schkop.project;
import android.os.Bundle;
import android.app.Activity;
import android.content.Intent;
import android.view.Menu;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;
public class cv_1112pj12 extends Activity {
Button bn0, bn1, bn2, bn3;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.cv_1112pj12);
//
bn0 = (Button) findViewById(R.id.button0);
bn1 = (Button) findViewById(R.id.button1);
bn2 = (Button) findViewById(R.id.button2);
bn3 = (Button) findViewById(R.id.button3);
bn0.setOnClickListener(new OnClickListener(){
@Override
public void onClick(View arg0) {
// TODO Auto-generated method stub
Intent it0 = new Intent(getApplicationContext(), Main.class);
startActivity(it0);
}
});
bn1.setOnClickListener(new OnClickListener(){
@Override
public void onClick(View arg0) {
// TODO Auto-generated method stub
Intent it1 = new Intent(getApplicationContext(), Store.class);
startActivity(it1);
}
});
bn2.setOnClickListener(new OnClickListener(){
@Override
public void onClick(View arg0) {
// TODO Auto-generated method stub
Intent it2 = new Intent(getApplicationContext(), News_feed.class);
startActivity(it2);
}
});
bn3.setOnClickListener(new OnClickListener(){
@Override
public void onClick(View arg0) {
// TODO Auto-generated method stub
Intent it3 = new Intent(getApplicationContext(), cv_1112pj12_play.class);
startActivity(it3);
}
});
//
}
@Override
public boolean onCreateOptionsMenu(Menu menu) {
// Inflate the menu; this adds items to the action bar if it is present.
getMenuInflater().inflate(R.menu.main, menu);
return true;
}
}
cv_1112pj12.xml
<ScrollView xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="#e9e9e9"
android:textColor="#000000"
android:scrollbars="vertical">
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:orientation="vertical"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context=".Main" >
<LinearLayout
android:orientation="horizontal"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="#000000">
<Button
android:id="@+id/button0"
android:layout_width="wrap_content"
android:layout_height="50dp"
android:text="@string/tab1"
android:textColor="#000000"
android:background="#ffffff"
android:layout_weight="1" />
<Button
android:id="@+id/button1"
android:layout_width="wrap_content"
android:layout_height="50dp"
android:text="@string/tab2"
android:textColor="#ffffff"
android:background="#2f4444"
android:layout_weight="1"/>
<Button
android:id="@+id/button2"
android:layout_width="wrap_content"
android:layout_height="50dp"
android:text="@string/tab3"
android:textColor="#ffffff"
android:background="#2f4444"
android:layout_weight="1" />
</LinearLayout>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:textColor="#000000"
android:background="#e9e9e9"
android:orientation="vertical" >
<ImageView
android:id="@+id/imageView11"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:textColor="#000000"
android:background="#e9e9e9"
android:src="@drawable/cv_1112pj12"/>
<TextView
android:id="@+id/textView12"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:textColor="#000000"
android:background="#e9e9e9"
android:text="@string/tab2_1112pj12"
android:textAppearance="?android:attr/textAppearanceLarge" />
<TextView
android:id="@+id/textView13"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:textColor="#000000"
android:background="#e9e9e9"
android:text="@string/tab2_1112pj12_desc"
android:textAppearance="?android:attr/textAppearanceMedium" />
<TextView
android:id="@+id/textView14"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:textColor="#000000"
android:background="#e9e9e9"
android:text="@string/tab_space"
android:textAppearance="?android:attr/textAppearanceLarge" />
<TextView
android:id="@+id/textView13"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:textColor="#000000"
android:background="#e9e9e9"
android:text="@string/tab2_noti"
android:textAppearance="?android:attr/textAppearanceMedium" />
<TextView
android:id="@+id/textView14"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:textColor="#000000"
android:background="#e9e9e9"
android:text="@string/tab2_noti_desc"
android:textAppearance="?android:attr/textAppearanceSmall" />
<Button
android:id="@+id/button3"
android:layout_width="match_parent"
android:layout_height="50dp"
android:textColor="#ffffff"
android:background="#2f4444"
android:layout_gravity="bottom"
android:layout_marginTop="60dp"
android:text="@string/tab2_watch" />
</LinearLayout>
</LinearLayout>
</ScrollView>
这是xml和java文件,我应该在这些文件中添加什么代码?并且请在评论时发布所有代码(不仅是修正部分),谢谢
答案 0 :(得分:0)
使用以下代码播放视频。
Intent intent = new Intent(Intent.ACTION_VIEW);
intent.setDataAndType(Uri.parse(sampleFile), "video/mp4");
startActivity(intent);
sampleFile是您的视频网址。