drawable-[h,m,l]dpi フォルダーにさまざまなサイズのビデオを配置して、再生するイントロ ビデオがあります。常にポートレートモードで再生するように設定しています。
レイアウト
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent" >
<VideoView android:id="@+id/myvideoview"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:layout_gravity="center"
android:orientation="vertical"/>
</RelativeLayout>
マニフェスト
<activity android:name=".IntroActivity"
android:configChanges="keyboardHidden|orientation|screenSize"
android:screenOrientation="portrait"
android:label="@string/app_name">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
ただし、ビデオは 4.0.4 タブレットでは横向きで再生されますが、2.2.1 スマートフォンでは機能します。
紹介活動
protected void onStart()
{
try
{
setContentView(R.layout.intro);
videoHolder = (VideoView)findViewById(R.id.myvideoview);
Uri video = Uri.parse("android.resource://" + getPackageName() + "/" + R.drawable.intro);
videoHolder.setVideoURI(video);
videoHolder.setOnCompletionListener(new MediaPlayer.OnCompletionListener()
{
public void onCompletion(MediaPlayer mp)
{
if (touched == false)
{
startActivity(new Intent("com.eg.flupaniclite.menu"));
}
}
});
videoHolder.setOnErrorListener(new MediaPlayer.OnErrorListener()
{
@Override
public boolean onError(MediaPlayer mp, int what, int extra)
{
if (touched == false)
{
startActivity(new Intent("com.eg.flupaniclite.menu"));
}
return false;
}
});
videoHolder.start();
}
catch (Exception e)
{
if (touched == false)
{
startActivity(new Intent("com.eg.flupaniclite.menu"));
}
}
super.onStart();
}