我剛開始使用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();
}
}
}
所以當我點擊我的按鈕,它只是說「應用視頻測試已意外停止,請重試。」
有什麼想法嗎?
比較字符串使用等號('path.equals( 「」)'),而不是'路徑== 「」' – MByD 2011-05-03 21:45:28
請加一個logcat的日誌 – MByD 2011-05-03 21:51:55
做==工作正常。此外,這不會解決問題 – Ronnie 2011-05-03 22:05:37