/*
* Copyright (C) 2006 The Android Open Source Project
* Copyright (c) 2014 Chukong Technologies Inc.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.cocos2dx.lib;
import android.app.AlertDialog;
import android.content.DialogInterface;
import android.content.Intent;
import android.content.res.AssetFileDescriptor;
import android.content.res.Resources;
import android.media.AudioManager;
import android.media.MediaPlayer;
import android.media.MediaPlayer.OnErrorListener;
import android.net.Uri;
import android.util.Log;
import android.view.Gravity;
import android.view.MotionEvent;
import android.view.SurfaceHolder;
import android.view.SurfaceView;
import android.widget.FrameLayout;
import android.widget.MediaController.MediaPlayerControl;
import com.chukong.cocosplay.client.CocosPlayClient;
import java.io.IOException;
import java.util.Map;
public class Cocos2dxVideoView extends SurfaceView implements MediaPlayerControl {
private String TAG = "Cocos2dxVideoView";
private Uri mVideoUri;
private int mDuration;
// all possible internal states
private static final int STATE_ERROR = -1;
private static final int STATE_IDLE = 0;
private static final int STATE_PREPARING = 1;
private static final int STATE_PREPARED = 2;
private static final int STATE_PLAYING = 3;
private static final int STATE_PAUSED = 4;
private static final int STATE_PLAYBACK_COMPLETED = 5;
/**
* mCurrentState is a VideoView object's current state.
* mTargetState is the state that a method caller intends to reach.
* For instance, regardless the VideoView object's current state,
* calling pause() intends to bring the object to a target state
* of STATE_PAUSED.
*/
private int mCurrentState = STATE_IDLE;
private int mTargetState = STATE_IDLE;
// All the stuff we need for playing and showing a video
private SurfaceHolder mSurfaceHolder = null;
private MediaPlayer mMediaPlayer = null;
private int mVideoWidth = 0;
private int mVideoHeight = 0;
private OnVideoEventListener mOnVideoEventListener;
private MediaPlayer.OnPreparedListener mOnPreparedListener;
private int mCurrentBufferPercentage;
private OnErrorListener mOnErrorListener;
// recording the seek position while preparing
private int mSeekWhenPrepared;
protected Cocos2dxActivity mCocos2dxActivity = null;
protected int mViewLeft = 0;
protected int mViewTop = 0;
protected int mViewWidth = 0;
protected int mViewHeight = 0;
protected int mVisibleLeft = 0;
protected int mVisibleTop = 0;
protected int mVisibleWidth = 0;
protected int mVisibleHeight = 0;
protected boolean mFullScreenEnabled = false;
protected int mFullScreenWidth = 0;
protected int mFullScreenHeight = 0;
private int mViewTag = 0;
public Cocos2dxVideoView(Cocos2dxActivity activity,int tag) {
super(activity);
mViewTag = tag;
mCocos2dxActivity = activity;
initVideoView();
}
@Override
protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) {
if (mVideoWidth == 0 || mVideoHeight == 0) {
setMeasuredDimension(mViewWidth, mViewHeight);
Log.i(TAG, ""+mViewWidth+ ":" +mViewHeight);
}
else {
setMeasuredDimension(mVisibleWidth, mVisibleHeight);
Log.i(TAG, ""+mVisibleWidth+ ":" +mVisibleHeight);
}
}
public void setVideoRect(int left, int top, int maxWidth, int maxHeight) {
mViewLeft = left;
mViewTop = top;
mViewWidth = maxWidth;
mViewHeight = maxHeight;
fixSize(mViewLeft, mViewTop, mViewWidth, mViewHeight);
}
public void setFullScreenEnabled(boolean enabled, int width, int height) {
if (mFullScreenEnabled != enabled) {
mFullScreenEnabled = enabled;
if (width != 0 && height != 0) {
mFullScreenWidth = width;
mFullScreenHeight = height;
}
fixSize();
}
}
public int resolveAdjustedSize(int desiredSize, int measureSpec) {
int result = desiredSize;
int specMode = MeasureSpec.getMode(measureSpec);
int specSize = MeasureSpec.getSize(measureSpec);
switch (specMode) {
case MeasureSpec.UNSPECIFIED:
/* Parent says we can be as big as we want. Just don't be larger
* than max size imposed on ourselves.
*/
result = desiredSize;
break;
case MeasureSpec.AT_MOST:
/* Parent says we can be as big as we want, up to specSize.
* Don't be larger than specSize, and don't be larger than
* the max size imposed on ourselves.
*/
result = Math.min(desiredSize, specSize);
break;
case MeasureSpec.EXACTLY:
// No choice. Do what we are told.
result = specSize;
break;
}
return result;
}
private boolean mNeedResume = false;
@Override
public void setVisibility(int visibility) {
if (visibility == INVISIBLE) {
mNeedResume = isPlaying();
if (mNeedResume) {
mSeekWhenPrepared = getCurrentPosition();
}
}
else if (mNeedResume){
start();
mNeedResume = false;
}
super.setVisibility(visibility);
}
private void initVideoView() {
mVideoWidth = 0;
mVideoHeight = 0;
getHolder().addCallback(mSHCallback);
//Fix issue#11516:Can't play video on Android 2.3.x
getHolder().setType(SurfaceHolder.SURFACE_TYPE_PUSH_BUFFERS);
setFocusable(true);
setFocusableInTouchMode(true);
mCurrentState = STATE_IDLE;
mTargetState = STATE_IDLE;
}
@Override
public boolean onTouchEvent(MotionEvent event) {
if((event.getAction() & MotionEvent.ACTION_MASK) == MotionEvent.ACTION_UP)
{
if (isPlaying()) {
pause();
} else if(mCurrentState == STATE_PAUSED){
resume();
}
}
return true;
}
private boolean mIsAssetRouse = false;
private String mVideoFilePath = null;
private static final String AssetResourceRoot = "assets/";
public void setVideoFileName(String path) {
if (path.startsWith(AssetResourceRoot)) {
path = path.substring(AssetResourceRoot.length());
}
if (CocosPlayClient.isEnabled() && !CocosPlayClient.isDemo()) {
CocosPlayClient.updateAssets(path);
}
CocosPlayClient.notifyFileLoaded(path);
if (path.startsWith("/")) {
mIsAssetRouse = false;
setVideoURI(Uri.parse(path),null);
}
else {
mVideoFilePath = path;
mIsAssetRouse = true;
setVideoURI(Uri.parse(path),null);
}
}
public void setVideoURL(String url) {
mIsAssetRouse = false;
setVideoURI(Uri.parse(url), null);
}
/**
* @hide
没有合适的资源?快使用搜索试试~ 我知道了~
cocos2dx接入微信SDK实例(分享文本和图片)。c++代码。
共48个文件
java:31个
png:4个
h:2个
需积分: 50 38 下载量 184 浏览量
2017-11-24
12:18:39
上传
评论
收藏 8.98MB ZIP 举报
温馨提示
此上传的不是整个项目。此安装包包含了cocos2dx。c++项目的bin(打包apk)。classes(具体代码)。libs(微信工具包)。src(java代码)。Resources(资源)。AndroidManifest.xml
资源推荐
资源详情
资源评论
收起资源包目录
微信分享实例.zip (48个子文件)
微信分享实例
bin
debug
android
ShareToWX-debug.apk 4.53MB
Resources
res
Default
Button_Disable.png 1KB
Button_Press.png 1KB
Button_Normal.png 1KB
MainScene.csb 3KB
HelloWorld.png 208KB
AndroidManifest.xml 2KB
libs
wechat-sdk-android-with-mta.jar 210KB
android-async-http-1.4.8.jar 104KB
armeabi
libcocos2dcpp.so 10.57MB
gdbserver 400KB
gdb.setup 4KB
src
wxapi
WXEntryActivity.java 1KB
org
cocos2dx
cpp
AppActivity.java 1KB
lib
Cocos2dxHandler.java 4KB
Cocos2dxMusic.java 9KB
Cocos2dxEditBoxHelper.java 16KB
Cocos2dxWebView.java 5KB
Cocos2dxRenderer.java 7KB
Cocos2dxAccelerometer.java 6KB
Cocos2dxTextInputWraper.java 5KB
Cocos2dxWebViewHelper.java 9KB
ResizeLayout.java 3KB
GameControllerUtils.java 894B
Cocos2dxTypefaces.java 3KB
Cocos2dxEditBox.java 9KB
Cocos2dxBitmap.java 9KB
Cocos2dxDownloader.java 11KB
GameControllerAdapter.java 3KB
Cocos2dxHelper.java 21KB
Cocos2dxActivity.java 16KB
Cocos2dxVideoView.java 24KB
Cocos2dxSound.java 13KB
Cocos2dxLuaJavaBridge.java 2KB
Cocos2dxGLSurfaceView.java 17KB
Cocos2dxVideoHelper.java 14KB
Cocos2dxLocalStorage.java 5KB
Cocos2dxJavascriptJavaBridge.java 1KB
Cocos2dxHttpURLConnection.java 14KB
GameControllerDelegate.java 2KB
com
enhance
gameservice
IGameTuningService.aidl 258B
chukong
cocosplay
client
CocosPlayClient.java 2KB
share
game
WXapi.java 4KB
Util.java 6KB
Classes
AppDelegate.h 987B
HelloWorldScene.h 523B
HelloWorldScene.cpp 3KB
AppDelegate.cpp 2KB
共 48 条
- 1
资源评论
Keary丶
- 粉丝: 2
- 资源: 5
上传资源 快速赚钱
- 我的内容管理 展开
- 我的资源 快来上传第一个资源
- 我的收益 登录查看自己的收益
- 我的积分 登录查看自己的积分
- 我的C币 登录后查看C币余额
- 我的收藏
- 我的下载
- 下载帮助
安全验证
文档复制为VIP权益,开通VIP直接复制
信息提交成功