80,355
社区成员
发帖
与我相关
我的任务
分享
public abstract class Cocos2dxActivity extends Activity implements Cocos2dxHelperListener {
@Override
protected void onCreate(final Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
// FrameLayout
ViewGroup.LayoutParams framelayout_params =
new ViewGroup.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT,
ViewGroup.LayoutParams.MATCH_PARENT);
mFrameLayout = new FrameLayout(this);
mFrameLayout.setLayoutParams(framelayout_params);
// Cocos2dxEditText layout
ViewGroup.LayoutParams edittext_layout_params =
new ViewGroup.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT,
ViewGroup.LayoutParams.WRAP_CONTENT);
Cocos2dxEditText edittext = new Cocos2dxEditText(this);
edittext.setLayoutParams(edittext_layout_params);
// ...add to FrameLayout
mFrameLayout.addView(edittext);
// Cocos2dxGLSurfaceView
this.mGLSurfaceView = this.onCreateView();
// ...add to FrameLayout
mFrameLayout.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(mFrameLayout);
}
}
public class MainActivity extends Cocos2dxActivity {
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
}
}
public class VideoView extends SurfaceView implements
<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="#0099cc"
tools:context=".PlayerActivity" >
<tv.danmaku.ijk.media.widget.VideoView
android:id="@+id/video_view"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:layout_gravity="center" />
<LinearLayout
android:id="@+id/buffering_indicator"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:focusable="false"
android:focusableInTouchMode="false"
android:orientation="vertical"
android:visibility="gone" >
<TextView
android:id="@+id/buffering_msg"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:adjustViewBounds="true"
android:ellipsize="marquee"
android:marqueeRepeatLimit="0"
android:scaleType="centerInside"
android:singleLine="true"
android:text="@string/buffering"
android:textSize="12sp" />
<ProgressBar
android:id="@+id/buffering_progress"
style="@android:style/Widget.ProgressBar.Large"
android:layout_width="60dip"
android:layout_height="60dip" />
</LinearLayout>
</FrameLayout>
public class VideoPlayerActivity extends Activity {
private VideoView mVideoView;
private View mBufferingIndicator;
private MediaController mMediaController;
private String mVideoPath;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_player);
IjkMediaPlayer.loadLibrariesOnce(null);
IjkMediaPlayer.native_profileBegin("libijkplayer.so");
mVideoPath = getIntent().getStringExtra("videoPath");
Intent intent = getIntent();
String intentAction = intent.getAction();
if (!TextUtils.isEmpty(intentAction) && intentAction.equals(Intent.ACTION_VIEW)) {
mVideoPath = intent.getDataString();
}
mBufferingIndicator = findViewById(R.id.buffering_indicator);
mMediaController = new MediaController(this);
mVideoView = (VideoView) findViewById(R.id.video_view);
mVideoView.setMediaController(mMediaController);
mVideoView.setMediaBufferingIndicator(mBufferingIndicator);
mVideoView.setVideoPath(mVideoPath);
mVideoView.requestFocus();
mVideoView.start();
}
@Override
protected void onDestroy() {
super.onDestroy();
IjkMediaPlayer.native_profileEnd();
}
}