2013-03-16 237 views
1

我有一个简单的按钮,我希望通过点击此按钮播放URL视频(xxx.mp4),但没有videoView或webView。所以如果我点击按钮,手机会询问我选择播放视频的内部播放器。用手机内置视频播放器播放视频

按钮来播放视频: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

使用以下代码播放视频。

Intent intent = new Intent(Intent.ACTION_VIEW); 
     intent.setDataAndType(Uri.parse(sampleFile), "video/mp4"); 
     startActivity(intent); 

sampleFile是您的视频网址。

+0

你解决这个问题吗? – 2013-03-16 13:13:41

+0

以下是一些错误: -intent无法解析;语法错误,插入“)”以完成MethodInvocation;语法错误,插入“;”完成声明;在Uri类型中的方法parse(String)不适用于参数() – 2013-03-17 07:40:28

+0

我该如何解决这些错误? – 2013-03-17 07:47:56