天天看點

Android模拟器放出視訊,android模拟器中播放視訊(有聲無影等問題的解決)

今天按照《Android應用開發揭秘》中的代碼做了個播放視訊的小例子,播放後發現有聲無音,發現是視訊分辨率過大造成的。

使用格式工廠工具把MP4轉換一下就可以了。

轉換的配置如圖

Android模拟器放出視訊,android模拟器中播放視訊(有聲無影等問題的解決)

轉換後的檔案屬性如下:

Android模拟器放出視訊,android模拟器中播放視訊(有聲無影等問題的解決)

那個幀速率是重點,要調低。

相關的代碼:

package com.yarin.android.Examples_07_03;

import android.app.Activity;

import android.content.pm.ActivityInfo;

import android.os.Bundle;

import android.util.Log;

import android.view.View;

import android.view.View.OnClickListener;

import android.widget.Button;

import android.widget.MediaController;

import android.widget.VideoView;

import android.media.*;

import android.view.Window;

import android.view.WindowManager;

public class Activity01 extends Activity

{

private static final String TAG="VideoView";

@Override

public void onCreate(Bundle savedInstanceState)

{

super.onCreate(savedInstanceState);

//不要标題

requestWindowFeature(Window.FEATURE_NO_TITLE);

//設定成全屏模式

getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN,

WindowManager.LayoutParams.FLAG_FULLSCREEN);

//強制為橫屏

setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_LANDSCAPE);

setContentView(R.layout.main);

final VideoView videoView = (VideoView) findViewById(R.id.VideoView01);

Button PauseButton = (Button) this.findViewById(R.id.PauseButton);

Button LoadButton = (Button) this.findViewById(R.id.LoadButton);

Button PlayButton = (Button) this.findViewById(R.id.PlayButton);

LoadButton.setOnClickListener(new OnClickListener()

{

public void onClick(View arg0)

{

videoView.setVideoPath("/mnt/sdcard/aaoceans-clip.mp4");

videoView.setMediaController(new MediaController(Activity01.this));

videoView.requestFocus();

}

});

PlayButton.setOnClickListener(new OnClickListener()

{

public void onClick(View arg0)

{

Log.v(TAG,"start");

videoView.start();

Log.v(TAG,"start OK");

}

});

PauseButton.setOnClickListener(new OnClickListener()

{

public void onClick(View arg0)

{

videoView.pause();

}

});

}

}

main.xml中要添加

android:id="@+id/VideoView01"

android:layout_width="fill_parent"

android:layout_height="fill_parent"

/>

android:layout_width="80px"

android:layout_height="wrap_content"

android:text="裝載"

android:layout_x="30px"

android:layout_y="300px"

/>

android:layout_width="80px"

android:layout_height="wrap_content"

android:text="播放"

android:layout_x="120px"

android:layout_y="300px"

/>

android:layout_width="80px"

android:layout_height="wrap_content"

android:text="暫停"

android:layout_x="210px"

android:layout_y="300px"

/> VideoView的布局屬性要設成fill_parent.