轉: Android上ffmpeg移植(4)-終結篇
今天終於在模擬器上面可以看到視訊了,雖然隨機性會有一些問題,但總體來說,效果還可以測試了avi和flv檔案,播放的都比較好,因為是模擬器,我設定的輸出格式是RGB565,這樣看起來可能色彩不是很好。
上層的呼叫完全是標準的java介面,應用程式是參考一本資料書上面的,程式碼如下:
package irdc.ex07_13;
import android.app.Activity;
import android.graphics.PixelFormat;
import android.media.MediaPlayer;
import android.net.Uri;
import android.os.Bundle;
import android.util.Log;
import android.view.View;
import android.widget.Button;
import android.widget.MediaController;
import android.widget.TextView;
import android.widget.Toast;
import android.widget.VideoView;
public class EX07_13 extends Activity
{
private TextView mTextView01;
private VideoView mVideoView01;
private String strVideoPath = "";
private Button mButton01, mButton02;
private String TAG = "HIPPO_VIDEOVIEW";
/* 預設判別是否安裝儲存卡flag為false */
private boolean bIfSDExist = false;
/** Called when the activity is first created. */
@Override
public void onCreate(Bundle savedInstanceState)
{
super.onCreate(savedInstanceState);
/* 全螢幕 */
getWindow
setContentView(R.layout.main);
/* 判斷儲存卡是否存在 */
if(android.os.Environment.getExternalStorageState().equals
(android.os.Environment.MEDIA_MOUNTED))
{
bIfSDExist = true;
}
else
{
bIfSDExist = false;
mMakeTextToast
(
getResources().getText(R.string.str_err_nosd).toString(),
true
);
}
mTextView01 = (TextView)findViewById(R.id.myTextView1);
mVideoView01 = (VideoView)findViewById(R.id.myVideoView1);
mButton01 = (Button)findViewById(R.id.myButton1);
mButton02 = (Button)findViewById(R.id.myButton2);
mButton01.setOnClickListener(new Button.OnClickListener()
{
@Override
public void onClick(View arg0)
{
// TODO Auto-generated method stub
/* 播放影片路徑1 */
strVideoPath = "file:///data/test.flv";
playVideo(strVideoPath);
}
});
mButton02.setOnClickListener(new Button.OnClickListener()
{
@Override
public void onClick(View arg0)
{
// TODO Auto-generated method stub
/* 播放影片路徑2 */
strVideoPath = "file:///data/test.avi";
playVideo(strVideoPath);
}
});
}
/* 自定義
private void playVideo(String strPath)
{
if(strPath!="")
{
/* 呼叫VideoURI方法,指定解析路徑 */
mVideoView01.setVideoURI(Uri.parse(strPath));
/* 設定控制Bar顯示於此Context中 */
mVideoView01.setMediaController
(new MediaController(EX07_13.this));
mVideoView01.requestFocus();
/* 呼叫VideoView.start()自動播放 */
mVideoView01.start();
if(mVideoView01.isPlaying())
{
/* 下程式不會被執行,因start()後尚需要preparing() */
mTextView01.setText("Now Playing:"+strPath);
Log.i(TAG, strPath);
}
}
}
public void mMakeTextToast(String str, boolean isLong)
{
if(isLong==true)
{
Toast.makeText(EX07_13.this, str, Toast.LENGTH_LONG).show();
}
else
{
Toast.makeText(EX07_13.this, str, Toast.LENGTH_SHORT).show();
}
}
}
因為我的sdk有點問題,沒有識別出來SD card,所以這裡把視訊都是push到data目錄
基本上移植的過程可以說告一段落,感覺androi的框架本身都不難,主要是看ffmpeg的介面api看了幾天,
然後音視訊同步的演算法還需要改正,建立了大概4個執行緒,這個還要仔細斟酌一下。