這可以通過更改libcocos2dx中的Cocos2dxActivity類來實現,以在其中添加VideoView。
首先,在libcocos2dx這個XML佈局添加到RES /佈局:
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/LinearLayout2"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="horizontal" >
<VideoView
android:id="@+id/video"
android:layout_width="0dp"
android:layout_height="fill_parent"
android:layout_weight="4" />
<FrameLayout
android:id="@+id/frame"
android:layout_width="0dp"
android:layout_height="match_parent"
android:layout_weight="6" >
</FrameLayout>
</LinearLayout>
這種佈局將是您的應用程序的新佈局。
其次,你必須在Cocos2dxActivity改變init()
方法是:
public void init() {
// Set our new layout as the content view
setContentView(R.layout.test);
// FrameLayout
//ViewGroup.LayoutParams framelayout_params =
//new ViewGroup.LayoutParams(ViewGroup.LayoutParams.FILL_PARENT,
//ViewGroup.LayoutParams.FILL_PARENT);
//FrameLayout framelayout = new FrameLayout(this);
//framelayout.setLayoutParams(framelayout_params);
Resources res = this.getResources();
int id = res.getIdentifier("YOUR_VIDEO_NAME_HERE", "raw", getPackageName());
if (id == 0) {
Log.e("Cocos2dx VIDEO", "ERROR! Resource id == 0");
Log.e("Cocos2dx VIDEO", "ERROR! Check name of video!");
} else {
VideoView vv = (VideoView) findViewById(R.id.video);
MediaController mc = new MediaController(this);
mc.setAnchorView(vv);
vv.setMediaController(mc);
vv.setVideoURI(Uri.parse("android.resource://" + getPackageName() + "/" + id));
vv.setOnPreparedListener(new MediaPlayer.OnPreparedListener() {
@Override
public void onPrepared(MediaPlayer mp) {
if (mp != null)
mp.setLooping(true);
});
vv.requestFocus();
vv.start();
}
FrameLayout framelayout = (FrameLayout) findViewById(R.id.frame);
// Cocos2dxEditText layout
ViewGroup.LayoutParams edittext_layout_params =
new ViewGroup.LayoutParams(ViewGroup.LayoutParams.FILL_PARENT,
ViewGroup.LayoutParams.WRAP_CONTENT);
Cocos2dxEditText edittext = new Cocos2dxEditText(this);
edittext.setLayoutParams(edittext_layout_params);
// ...add to FrameLayout
framelayout.addView(edittext);
// Cocos2dxGLSurfaceView
this.mGLSurfaceView = this.onCreateView();
// ...add to FrameLayout
framelayout.addView(this.mGLSurfaceView);
// Switch to supported OpenGL (ARGB888) mode on emulator
if (isAndroidEmulator())
this.mGLSurfaceView.setEGLConfigChooser(8 , 8, 8, 8, 16, 0);
this.mGLSurfaceView.setCocos2dxRenderer(new Cocos2dxRenderer());
this.mGLSurfaceView.setCocos2dxEditText(edittext);
//// Set framelayout as the content view
//setContentView(framelayout);
}
這會給你覆蓋40%在屏幕的左側,您科科斯遊戲區域覆蓋60%的權VideView 。
您應該將您的視頻放在您的項目的res/raw文件夾中。
此外,這是僅限Android的解決方案(基於您在問題中提供的標籤)。要在iOS或其他平臺上實現這一點,您必須對這些平臺的cocos庫代碼進行其他更改。
編輯:記住清理(爲了安全起見)並重建庫。
你怎麼玩你的視頻,通過哪個API?如果您使用的是Apple SDK中的AV API,則視頻窗口可能會將屏幕覆蓋在根場景的cocos窗口之上,具體取決於您的設置。一種方法是設法在特定的CCLayer中播放視頻。 –