2013-03-16 236 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