[英]how to play .3GP video file in android
您好,我想在Android手機中播放.3GP視頻文件。 我嘗試了下面的代碼,但顯示無法播放video.so,請告訴我我該怎么做
這是我的代碼
public class VideoPlay extends Activity {
private String path ;
private VideoView mVideoView;
@Override
public void onCreate(Bundle icicle) {
super.onCreate(icicle);
setContentView(R.layout.videoplay);
path="http://www.boodang.com/api/videobb/101009_Pure.3gp";
mVideoView = (VideoView) findViewById(R.id.video);
if (path == "") {
// Tell the user to provide a media file URL/path.
Toast.makeText(
VideoPlay.this,
"Please edit VideoViewDemo Activity, and set path"
+ " variable to your media file URL/path",
Toast.LENGTH_LONG).show();
} else {
/*
* Alternatively,for streaming media you can use
* mVideoView.setVideoURI(Uri.parse(URLstring));
*/
mVideoView.setVideoPath(path);
mVideoView.setMediaController(new MediaController(this));
mVideoView.requestFocus();
}
}
}
XML布局是
<?xml version="1.0" encoding="utf-8"?>
<FrameLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent">
<VideoView
android:id="@+id/video"
android:layout_width="320px"
android:layout_height="240px">
</VideoView>
</FrameLayout>
檢查Android SDK演示中的以下代碼
package com.example.android.apis.media;
import com.example.android.apis.R;
import android.app.Activity;
import android.os.Bundle;
import android.widget.MediaController;
import android.widget.Toast;
import android.widget.VideoView;
public class VideoViewDemo extends Activity {
/**
* TODO: Set the path variable to a streaming video URL or a local media
* file path.
*/
private String path = "";
private VideoView mVideoView;
@Override
public void onCreate(Bundle icicle) {
super.onCreate(icicle);
setContentView(R.layout.videoview);
mVideoView = (VideoView) findViewById(R.id.surface_view);
if (path == "") {
// Tell the user to provide a media file URL/path.
Toast.makeText(
VideoViewDemo.this,
"Please edit VideoViewDemo Activity, and set path"
+ " variable to your media file URL/path",
Toast.LENGTH_LONG).show();
} else {
/*
* Alternatively,for streaming media you can use
* mVideoView.setVideoURI(Uri.parse(URLstring));
*/
mVideoView.setVideoPath(path);
mVideoView.setMediaController(new MediaController(this));
mVideoView.requestFocus();
}
}
}
videoview.xml
<VideoView
android:id="@+id/surface_view"
android:layout_width="320px"
android:layout_height="240px"
/>
本文提供的代碼與您的示例相似,但是有一些區別,尤其是video.start
和示例完全缺少MediaController.show
。
我建議稍微清理一下代碼,然后嘗試上述文章中的建議。 文章討論中也有一些很好的反饋。
正如@Peter Lillevold建議的那樣,您應首先嘗試視頻播放器的參考實現。 以下是一些鏈接:
嘗試使用已知工作視頻文件的這些播放器, 這篇文章中有一些鏈接。 如果您實現播放器,並且這些參考視頻有效,但您的.3gp視頻沒有,則問題可能是視頻文件本身未按標准編碼。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.