Merge pull request #12095 from jianglong0156/videoplayer

add videoplayer jsb
This commit is contained in:
pandamicro 2015-06-02 17:35:56 +08:00
commit 613e0f73b7
10 changed files with 235 additions and 7 deletions

View File

@ -0,0 +1,49 @@
#include "jsb_cocos2dx_experimental_video_manual.h"
#if (CC_TARGET_PLATFORM == CC_PLATFORM_ANDROID || CC_TARGET_PLATFORM == CC_PLATFORM_IOS)
#include "UIVideoPlayer.h"
#include "ScriptingCore.h"
#include "cocos2d_specifics.hpp"
#include "cocos2d.h"
using namespace cocos2d;
static bool jsb_cocos2dx_experimental_ui_VideoPlayer_addEventListener(JSContext *cx, uint32_t argc, jsval *vp)
{
JSObject *obj = JS_THIS_OBJECT(cx, vp);
js_proxy_t *proxy = jsb_get_js_proxy(obj);
experimental::ui::VideoPlayer* cobj = (experimental::ui::VideoPlayer *)(proxy ? proxy->ptr : NULL);
JSB_PRECONDITION2( cobj, cx, false, "Invalid Native Object");
if(argc == 1){
JS::CallArgs args = JS::CallArgsFromVp(argc, vp);
std::shared_ptr<JSFunctionWrapper> func(new JSFunctionWrapper(cx, obj, args.get(0)));
cobj->addEventListener([=](Ref* widget, experimental::ui::VideoPlayer::EventType type)->void{
jsval arg[2];
js_proxy_t *proxy = js_get_or_create_proxy(cx, widget);
if(proxy)
arg[0] = OBJECT_TO_JSVAL(proxy->obj);
else
arg[0] = JSVAL_NULL;
arg[1] = int32_to_jsval(cx, (int32_t)type);
JS::RootedValue rval(cx);
bool ok = func->invoke(2, arg, &rval);
if (!ok && JS_IsExceptionPending(cx)) {
JS_ReportPendingException(cx);
}
});
return true;
}
}
extern JSObject* jsb_cocos2d_experimental_ui_VideoPlayer_prototype;
void register_all_cocos2dx_experimental_video_manual(JSContext* cx, JS::HandleObject global)
{
JS_DefineFunction(cx, JS::RootedObject(cx, jsb_cocos2d_experimental_ui_VideoPlayer_prototype), "addEventListener", jsb_cocos2dx_experimental_ui_VideoPlayer_addEventListener, 1, JSPROP_ENUMERATE | JSPROP_PERMANENT);
}
#endif

View File

@ -0,0 +1,9 @@
#ifndef __jsb_cocos2dx_experimental_video_manual__
#define __jsb_cocos2dx_experimental_video_manual__
#include "jsapi.h"
#include "jsfriendapi.h"
void register_all_cocos2dx_experimental_video_manual(JSContext* cx, JS::HandleObject global);
#endif /* defined(__jsb_cocos2dx_experimental_video_manual__) */

View File

@ -39,6 +39,7 @@ LOCAL_SRC_FILES := ../auto/jsb_cocos2dx_3d_auto.cpp \
../auto/jsb_cocos2dx_extension_auto.cpp \
../auto/jsb_cocos2dx_3d_extension_auto.cpp \
../auto/jsb_cocos2dx_experimental_webView_auto.cpp \
../auto/jsb_cocos2dx_experimental_video_auto.cpp \
../auto/jsb_cocos2dx_spine_auto.cpp \
../auto/jsb_cocos2dx_auto.cpp \
../auto/jsb_cocos2dx_studio_auto.cpp \
@ -56,6 +57,7 @@ LOCAL_SRC_FILES := ../auto/jsb_cocos2dx_3d_auto.cpp \
../manual/jsb_opengl_registration.cpp \
../manual/jsb_event_dispatcher_manual.cpp \
../manual/3d/jsb_cocos2dx_3d_manual.cpp \
../manual/experimental/jsb_cocos2dx_experimental_video_manual.cpp \
../manual/experimental/jsb_cocos2dx_experimental_webView_manual.cpp \
../manual/chipmunk/js_bindings_chipmunk_auto_classes.cpp \
../manual/chipmunk/js_bindings_chipmunk_functions.cpp \

View File

@ -172,6 +172,10 @@
83A5661A18DA878400FC31A0 /* jsb_socketio.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 83A5661718DA878400FC31A0 /* jsb_socketio.cpp */; };
83A5661B18DA878400FC31A0 /* jsb_socketio.h in Headers */ = {isa = PBXBuildFile; fileRef = 83A5661818DA878400FC31A0 /* jsb_socketio.h */; };
83A5661C18DA878400FC31A0 /* jsb_socketio.h in Headers */ = {isa = PBXBuildFile; fileRef = 83A5661818DA878400FC31A0 /* jsb_socketio.h */; };
B38AD56A1B1D384A0057DD7F /* jsb_cocos2dx_experimental_video_manual.cpp in Sources */ = {isa = PBXBuildFile; fileRef = B38AD5681B1D384A0057DD7F /* jsb_cocos2dx_experimental_video_manual.cpp */; };
B38AD56B1B1D384A0057DD7F /* jsb_cocos2dx_experimental_video_manual.h in Headers */ = {isa = PBXBuildFile; fileRef = B38AD5691B1D384A0057DD7F /* jsb_cocos2dx_experimental_video_manual.h */; };
B38AD56E1B1D38700057DD7F /* jsb_cocos2dx_experimental_video_auto.cpp in Sources */ = {isa = PBXBuildFile; fileRef = B38AD56C1B1D38700057DD7F /* jsb_cocos2dx_experimental_video_auto.cpp */; };
B38AD56F1B1D38700057DD7F /* jsb_cocos2dx_experimental_video_auto.hpp in Headers */ = {isa = PBXBuildFile; fileRef = B38AD56D1B1D38700057DD7F /* jsb_cocos2dx_experimental_video_auto.hpp */; };
BA4095C21A6F730A005E53F6 /* jsb_cocos2dx_studio_conversions.cpp in Sources */ = {isa = PBXBuildFile; fileRef = BA4095C01A6F730A005E53F6 /* jsb_cocos2dx_studio_conversions.cpp */; };
BA4095C31A6F730A005E53F6 /* jsb_cocos2dx_studio_conversions.cpp in Sources */ = {isa = PBXBuildFile; fileRef = BA4095C01A6F730A005E53F6 /* jsb_cocos2dx_studio_conversions.cpp */; };
BA4095C41A6F730A005E53F6 /* jsb_cocos2dx_studio_conversions.h in Headers */ = {isa = PBXBuildFile; fileRef = BA4095C11A6F730A005E53F6 /* jsb_cocos2dx_studio_conversions.h */; };
@ -292,6 +296,10 @@
4BE089EA1ADF967400D65D4B /* jsb_cocos2dx_experimental_webView_manual.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = jsb_cocos2dx_experimental_webView_manual.h; sourceTree = "<group>"; };
83A5661718DA878400FC31A0 /* jsb_socketio.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = jsb_socketio.cpp; sourceTree = "<group>"; };
83A5661818DA878400FC31A0 /* jsb_socketio.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = jsb_socketio.h; sourceTree = "<group>"; };
B38AD5681B1D384A0057DD7F /* jsb_cocos2dx_experimental_video_manual.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; name = jsb_cocos2dx_experimental_video_manual.cpp; path = experimental/jsb_cocos2dx_experimental_video_manual.cpp; sourceTree = "<group>"; };
B38AD5691B1D384A0057DD7F /* jsb_cocos2dx_experimental_video_manual.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = jsb_cocos2dx_experimental_video_manual.h; path = experimental/jsb_cocos2dx_experimental_video_manual.h; sourceTree = "<group>"; };
B38AD56C1B1D38700057DD7F /* jsb_cocos2dx_experimental_video_auto.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = jsb_cocos2dx_experimental_video_auto.cpp; sourceTree = "<group>"; };
B38AD56D1B1D38700057DD7F /* jsb_cocos2dx_experimental_video_auto.hpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.h; path = jsb_cocos2dx_experimental_video_auto.hpp; sourceTree = "<group>"; };
BA4095C01A6F730A005E53F6 /* jsb_cocos2dx_studio_conversions.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = jsb_cocos2dx_studio_conversions.cpp; sourceTree = "<group>"; };
BA4095C11A6F730A005E53F6 /* jsb_cocos2dx_studio_conversions.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = jsb_cocos2dx_studio_conversions.h; sourceTree = "<group>"; };
BA623DFC191A195F00761F37 /* jsb_pluginx_basic_conversions.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; name = jsb_pluginx_basic_conversions.cpp; path = ../../../../plugin/jsbindings/manual/jsb_pluginx_basic_conversions.cpp; sourceTree = "<group>"; };
@ -357,6 +365,8 @@
1A119E2E18BDF19200352BAA /* auto */ = {
isa = PBXGroup;
children = (
B38AD56C1B1D38700057DD7F /* jsb_cocos2dx_experimental_video_auto.cpp */,
B38AD56D1B1D38700057DD7F /* jsb_cocos2dx_experimental_video_auto.hpp */,
4BE089E01ADF965E00D65D4B /* jsb_cocos2dx_experimental_webView_auto.cpp */,
4BE089E11ADF965E00D65D4B /* jsb_cocos2dx_experimental_webView_auto.hpp */,
42638FFB1B0EC1B7004C53A2 /* jsb_cocos2dx_physics3d_auto.cpp */,
@ -578,6 +588,8 @@
42AD25701AFF9DFC000176E2 /* experimental */ = {
isa = PBXGroup;
children = (
B38AD5681B1D384A0057DD7F /* jsb_cocos2dx_experimental_video_manual.cpp */,
B38AD5691B1D384A0057DD7F /* jsb_cocos2dx_experimental_video_manual.h */,
4B22F4A71B159A7A0044C14E /* jsb_cocos2dx_experimental_webView_manual.cpp */,
4B22F4A81B159A7A0044C14E /* jsb_cocos2dx_experimental_webView_manual.h */,
42AD25711AFF9E17000176E2 /* jsb_cocos2dx_experimental_manual.cpp */,
@ -667,6 +679,7 @@
buildActionMask = 2147483647;
files = (
1A119EA418BDF19200352BAA /* jsb_cocos2dx_studio_auto.hpp in Headers */,
B38AD56B1B1D384A0057DD7F /* jsb_cocos2dx_experimental_video_manual.h in Headers */,
1A119F0218BDF19200352BAA /* ScriptingCore.h in Headers */,
426390071B0EC1C6004C53A2 /* jsb_cocos2dx_physics3d_manual.h in Headers */,
1A119EBE18BDF19200352BAA /* cocos2d_specifics.hpp in Headers */,
@ -719,6 +732,7 @@
1A119E8618BDF19200352BAA /* jsb_cocos2dx_auto.hpp in Headers */,
BA623E12191A195F00761F37 /* jsb_pluginx_spidermonkey_specifics.h in Headers */,
1A119F0818BDF19200352BAA /* jsb_cocos2dx_spine_manual.h in Headers */,
B38AD56F1B1D38700057DD7F /* jsb_cocos2dx_experimental_video_auto.hpp in Headers */,
BA623E0A191A195F00761F37 /* jsb_pluginx_basic_conversions.h in Headers */,
BA623E14191A195F00761F37 /* pluginxUTF8.h in Headers */,
);
@ -858,6 +872,7 @@
4BE089E41ADF965E00D65D4B /* jsb_cocos2dx_experimental_webView_auto.cpp in Sources */,
1A119EF418BDF19200352BAA /* js_bindings_system_registration.cpp in Sources */,
42AD256D1AFF9D1A000176E2 /* jsb_cocos2dx_experimental.cpp in Sources */,
B38AD56E1B1D38700057DD7F /* jsb_cocos2dx_experimental_video_auto.cpp in Sources */,
1A119EBC18BDF19200352BAA /* cocos2d_specifics.cpp in Sources */,
426390051B0EC1C6004C53A2 /* jsb_cocos2dx_physics3d_manual.cpp in Sources */,
42638FFE1B0EC1B7004C53A2 /* jsb_cocos2dx_physics3d_auto.cpp in Sources */,
@ -884,6 +899,7 @@
1A119F0018BDF19200352BAA /* ScriptingCore.cpp in Sources */,
BA623E09191A195F00761F37 /* jsb_pluginx_basic_conversions.cpp in Sources */,
BA623E0D191A195F00761F37 /* jsb_pluginx_manual_callback.cpp in Sources */,
B38AD56A1B1D384A0057DD7F /* jsb_cocos2dx_experimental_video_manual.cpp in Sources */,
1A1D3B7918C44FD000922D3C /* jsb_event_dispatcher_manual.cpp in Sources */,
);
runOnlyForDeploymentPostprocessing = 0;

View File

@ -141,6 +141,11 @@ ccui.WebView.prototype._ctor = function(url){
url !== undefined && this.loadURL(url);
};
ccui.VideoPlayer.prototype._ctor = function(url){
this.init();
url !== undefined && this.setURL(url);
};
cc.Scale9Sprite.prototype._ctor = function(file, rect, capInsets){
rect = rect || cc.rect(0, 0, 0, 0);
capInsets = capInsets || cc.rect(0, 0, 0, 0);

View File

@ -418,6 +418,55 @@ ccui.WebView.prototype.setEventListener = function(event, callback){
}
};
/**
* The VideoPlayer support list of events
* @type {{PLAYING: string, PAUSED: string, STOPPED: string, COMPLETED: string}}
*/
ccui.VideoPlayer.EventType = {
PLAYING: "play",
PAUSED: "pause",
STOPPED: "stop",
COMPLETED: "complete"
};
ccui.VideoPlayer.prototype._setURL = ccui.VideoPlayer.prototype.setURL;
ccui.VideoPlayer.prototype.setURL = function (url) {
if (url.indexOf("http://") >= 0)
{
this._setURL(url);
}
else
{
this.setFileName(url);
}
};
ccui.VideoPlayer.prototype.setEventListener = function(event, callback){
if (!this.videoPlayerCallback)
{
this.videoPlayerCallback = function(sender, eventType){
cc.log("videoEventCallback eventType:" + eventType);
switch (eventType) {
case 0:
this["VideoPlayer_"+ccui.VideoPlayer.EventType.PLAYING] && this["VideoPlayer_"+ccui.VideoPlayer.EventType.PLAYING](sender);
break;
case 1:
this["VideoPlayer_"+ccui.VideoPlayer.EventType.PAUSED] && this["VideoPlayer_"+ccui.VideoPlayer.EventType.PAUSED](sender);
break;
case 2:
this["VideoPlayer_"+ccui.VideoPlayer.EventType.STOPPED] && this["VideoPlayer_"+ccui.VideoPlayer.EventType.STOPPED](sender);
break;
case 3:
this["VideoPlayer_"+ccui.VideoPlayer.EventType.COMPLETED] && this["VideoPlayer_"+ccui.VideoPlayer.EventType.COMPLETED](sender);
break;
default:
break;
}
};
this.addEventListener(this.videoPlayerCallback);
}
this["VideoPlayer_"+event] = callback;
};
/*
* UIWidget temporary solution to addChild
* addNode and addChild function should be merged in ccui.Widget

View File

@ -44,6 +44,11 @@
#include "experimental/jsb_cocos2dx_experimental_webView_manual.h"
#endif
#if (CC_TARGET_PLATFORM == CC_PLATFORM_IOS || CC_TARGET_PLATFORM == CC_PLATFORM_ANDROID)
#include "jsb_cocos2dx_experimental_video_auto.hpp"
#include "experimental/jsb_cocos2dx_experimental_video_manual.h"
#endif
USING_NS_CC;
USING_NS_CC_EXT;
using namespace CocosDenshion;
@ -132,6 +137,11 @@ bool AppDelegate::applicationDidFinishLaunching()
sc->addRegisterCallback(register_all_cocos2dx_experimental_webView_manual);
#endif
#if (CC_TARGET_PLATFORM == CC_PLATFORM_IOS || CC_TARGET_PLATFORM == CC_PLATFORM_ANDROID)
sc->addRegisterCallback(register_all_cocos2dx_experimental_video);
sc->addRegisterCallback(register_all_cocos2dx_experimental_video_manual);
#endif
sc->start();
sc->runScript("script/jsb_boot.js");
#if defined(COCOS2D_DEBUG) && (COCOS2D_DEBUG > 0)

View File

@ -3,18 +3,43 @@ var UIVideoPlayerTest = UIScene.extend({
onEnter: function(){
UIScene.prototype.onEnter.call(this);
var video = new ccui.VideoPlayer("cocosui/UITest/movie.mp4");
var video = new ccui.VideoPlayer("http://benchmark.cocos2d-x.org/cocosvideo.mp4");
video.setContentSize(320, 240);
video.setPosition(800/2, 450/2);
video.setScale(0.5);
window.video = video;
this.addChild(video);
video.setEventListener(ccui.VideoPlayer.EventType.PLAYING, function(sender){
cc.log("VideoPlayer PLAYING");
});
video.setEventListener(ccui.VideoPlayer.EventType.PAUSED, function(sender){
cc.log("VideoPlayer PAUSED");
});
video.setEventListener(ccui.VideoPlayer.EventType.STOPPED, function(sender){
cc.log("VideoPlayer STOPPED");
});
video.setEventListener(ccui.VideoPlayer.EventType.COMPLETED, function(sender){
cc.log("VideoPlayer COMPLETED");
});
ccui.VideoPlayer.EventType = {
PLAYING: "play",
PAUSED: "pause",
STOPPED: "stop",
COMPLETED: "complete"
};
var list = [
{ name: "PLAY", func: function(){
cc.log("play!");
video.play();
}},
{ name: "PLAYWEB", func: function(){
cc.log("play!");
video.setURL("http://benchmark.cocos2d-x.org/cocosvideo.mp4");
video.play();
}},
{ name: "PLAYNATIVE", func: function(){
cc.log("play!");
video.setURL("res/cocosvideo.mp4");
video.play();
}},
{ name: "STOP", func: function(){
cc.log("stop!");
video.stop();
@ -38,7 +63,7 @@ var UIVideoPlayerTest = UIScene.extend({
}},
{ name: "Full Screen", func: function(){
cc.log("setFullScreenEnabled!");
video.setFullScreenEnabled();
video.setFullScreenEnabled(true);
}},
{ name: "Scale", func: function(){
var scale = ((Math.random() * 0.5 + 0.2) * 100 | 0) / 100;
@ -60,7 +85,7 @@ var UIVideoPlayerTest = UIScene.extend({
var layer = this;
list.forEach(function(item, i){
var but = new ccui.Button();
but.setPosition( 140 + (i / 5 | 0) * 500, 300 - (i % 5) * 35);
but.setPosition( 140 + (i / 6 | 0) * 500, 300 - (i % 6) * 35);
but.setTitleText(item.name);
but.setZoomScale(0.3);
but.setPressedActionEnabled(true);

View File

@ -0,0 +1,62 @@
[cocos2dx_experimental_video]
# the prefix to be added to the generated functions. You might or might not use this in your own
# templates
prefix = cocos2dx_experimental_video
# create a target namespace (in javascript, this would create some code like the equiv. to `ns = ns || {}`)
# all classes will be embedded in that namespace
target_namespace = ccui
macro_judgement = #if (CC_TARGET_PLATFORM == CC_PLATFORM_ANDROID || CC_TARGET_PLATFORM == CC_PLATFORM_IOS)
android_headers = -I%(androidndkdir)s/platforms/android-14/arch-arm/usr/include -I%(androidndkdir)s/sources/cxx-stl/gnu-libstdc++/4.7/libs/armeabi-v7a/include -I%(androidndkdir)s/sources/cxx-stl/gnu-libstdc++/4.7/include -I%(androidndkdir)s/sources/cxx-stl/gnu-libstdc++/4.8/libs/armeabi-v7a/include -I%(androidndkdir)s/sources/cxx-stl/gnu-libstdc++/4.8/include
android_flags = -D_SIZE_T_DEFINED_
clang_headers = -I%(clangllvmdir)s/lib/clang/3.3/include
clang_flags = -nostdinc -x c++ -std=c++11 -U __SSE__
cocos_headers = -I%(cocosdir)s/cocos -I%(cocosdir)s/cocos/editor-support -I%(cocosdir)s/cocos/platform/android
cocos_flags = -DANDROID
cxxgenerator_headers =
# extra arguments for clang
extra_arguments = %(android_headers)s %(clang_headers)s %(cxxgenerator_headers)s %(cocos_headers)s %(android_flags)s %(clang_flags)s %(cocos_flags)s %(extra_flags)s
# what headers to parse
headers = %(cocosdir)s/cocos/ui/UIVideoPlayer.h
# what classes to produce code for. You can use regular expressions here. When testing the regular
# expression, it will be enclosed in "^$", like this: "^Menu*$".
classes = VideoPlayer
# what should we skip? in the format ClassName::[function function]
# ClassName is a regular expression, but will be used like this: "^ClassName$" functions are also
# regular expressions, they will not be surrounded by "^$". If you want to skip a whole class, just
# add a single "*" as functions. See bellow for several examples. A special class name is "*", which
# will apply to all class names. This is a convenience wildcard to be able to skip similar named
# functions from all classes.
skip = VideoPlayer::[addEventListener]
rename_functions =
rename_classes =
# for all class names, should we remove something when registering in the target VM?
remove_prefix =
# classes for which there will be no "parent" lookup
classes_have_no_parents =
# base classes which will be skipped when their sub-classes found them.
base_classes_to_skip =
# classes that create no constructor
# Set is special and we will use a hand-written constructor
abstract_classes =
# Determining whether to use script object(js object) to control the lifecycle of native(cpp) object or the other way around. Supported values are 'yes' or 'no'.
script_control_cpp = no

View File

@ -143,6 +143,7 @@ def main():
'cocos2dx_3d.ini' : ('cocos2dx_3d', 'jsb_cocos2dx_3d_auto'), \
'cocos2dx_3d_ext.ini' : ('cocos2dx_3d_extension', 'jsb_cocos2dx_3d_extension_auto'), \
'cocos2dx_experimental_webView.ini' : ('cocos2dx_experimental_webView', 'jsb_cocos2dx_experimental_webView_auto'), \
'cocos2dx_experimental_video.ini' : ('cocos2dx_experimental_video', 'jsb_cocos2dx_experimental_video_auto'), \
'cocos2dx_experimental.ini' : ('cocos2dx_experimental', 'jsb_cocos2dx_experimental'), \
'cocos2dx_physics3d.ini' : ('cocos2dx_physics3d', 'jsb_cocos2dx_physics3d_auto')
}