2011-05-03 48 views
0

我剛開始使用Android開發搞亂,我想簡單地播放視頻文件在網絡上的某個地方。我main.xml中看起來是這樣的:應用程序試圖在崩潰時使用VideoView

<?xml version="1.0" encoding="utf-8"?> 
    <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" 
     android:orientation="vertical" 
     android:layout_width="fill_parent" 
     android:layout_height="fill_parent" 
    > 
    <Button android:layout_height="wrap_content" android:id="@+id/button1" android:layout_width="wrap_content" android:text="@string/buttonText" android:onClick="clickHandler"></Button> 
    <VideoView android:layout_height="wrap_content" android:layout_width="match_parent" android:id="@+id/MyVideoView"></VideoView> 
</LinearLayout> 

和我的java文件看起來像這樣: 包com.dop.videoTest;

import android.app.Activity; 
import android.os.Bundle; 
import android.view.View; 
import android.widget.MediaController; 
import android.widget.Toast; 
import android.widget.VideoView; 


public class VideoTest extends Activity { 
    private String path = "http://commonsware.com/misc/test2.3gp"; 
    private VideoView mVideoView; 

    @Override 
    public void onCreate(Bundle savedInstanceState) { 
     super.onCreate(savedInstanceState); 
     setContentView(R.layout.main); 
    } 

    public void clickHandler(View view) 
    { 
     mVideoView = (VideoView) findViewById(R.id.MyVideoView); 

     if (path == "") { 
      Toast.makeText(
        VideoTest.this, 
        "Please edit VideoViewDemo Activity, and set path" 
          + " variable to your media file URL/path", 
        Toast.LENGTH_LONG).show(); 

     } else { 
      mVideoView.setVideoPath(path); 
      mVideoView.setMediaController(new MediaController(this)); 
      mVideoView.requestFocus(); 
     } 
    } 
} 

所以當我點擊我的按鈕,它只是說「應用視頻測試已意外停止,請重試。」

有什麼想法嗎?

+0

比較字符串使用等號('path.equals( 「」)'),而不是'路徑== 「」' – MByD 2011-05-03 21:45:28

+0

請加一個logcat的日誌 – MByD 2011-05-03 21:51:55

+0

做==工作正常。此外,這不會解決問題 – Ronnie 2011-05-03 22:05:37

回答

2

在你的代碼路徑是

private String path = "http://commonsware.com/misc/test2.3gp"; 

的VideoView將需要爲這個互聯網接入。 很可能你沒有在清單中設置互聯網許可。 發生這種情況的原因之一是當您的應用程序試圖訪問清單中需要顯式權限聲明的內容時。

Internet權限可以設置爲:

< uses-permission android:name="android.permission.INTERNET" /> 

檢查此鏈接: Android Manifest Documentation

+0

你是對的,補充說,這條線實際上使錯誤消失,視頻現在播放。爲什麼日食不會告訴你這樣的事情?我從來沒有想到會是這個原因。 – Ronnie 2011-05-03 22:06:18

+0

那麼,eclipse中的android支持是由android的google團隊開發的一個單獨的插件完成的(就我所知)。所以它們的一部分......不應該爲此而責備日食。我不知道android開發人員告訴你這樣的錯誤有多容易,但android開發支持還沒有接近成熟階段..但他們會相信。 – Rhymes 2011-05-03 22:44:32

+0

Gotcha ...你知道在java中做跟蹤或回聲的方法,所以它出現在eclipse控制檯中嗎? – Ronnie 2011-05-03 23:05:29