Giter Club home page Giter Club logo

cocos2dx_videoview_extends's Introduction

#cocos2dx 播放视频插件

##特性:

  • lua绑定
  • 播放完成事件回调
  • 支持android, ios平台

##使用示例:

-- 播放完之后的回调函数
local function videoFinish()
    print("================videoFinish")
    --恢复游戏, 和原来的声音
    cc.Director:getInstance():startAnimation();
    cc.SimpleAudioEngine:getInstance():resumeMusic();
end

-- 原游戏, 声音暂停
cc.Director:getInstance():stopAnimation();
cc.SimpleAudioEngine:getInstance():pauseMusic();
VideoView:play("res/video2.mp4",videoFinish)

##添加步骤:

  1. 一下文件拷贝到对应的目录里

     Classes/VideoView.h
     Classes/lua_videoview_extends.h
     Classes/lua_videoview_extends.cpp
    
     #android
     proj.android/src/cn/sharedream/game/VideoView.java
     proj.android/jni/VideoViewAndroidImp.cpp
    
     #ios
     proj.ios_mac/ios/VideoViewIOSImp.h
     proj.ios_mac/ios/VideoViewIOSImp.mm
    
  2. AppDelegate.cpp 注册VideoView 的lua 扩展

     #include "lua_videoview_extends.h"
    
     bool AppDelegate::applicationDidFinishLaunching()
     {
         ...
    
         auto engine = LuaEngine::getInstance();
         ScriptEngineManager::getInstance()->setScriptEngine(engine);
    
         //==============添加lua 扩展
         lua_State* L = engine->getLuaStack()->getLuaState();
         tolua_videoview_extension_open(L);
         //==============添加lua 扩展end
         
         if (engine->executeScriptFile("src/main.lua")) {
             return false;
         }
    
         return true;
     }
    
  3. android部分 修改jni 的 Android.mk 添加VideoViewAndroidImp.cpp 和 lua_videoview_extends.cpp 编译

     LOCAL_SRC_FILES := ... \
     	VideoViewAndroidImp.cpp \
     	../../Classes/lua_videoview_extends.cpp \
         ...
    

##TODO:

  • 播放时点击视频回调

##文件说明

Classes/VideoView.h:

		VideoView类接口定义

Classes/lua_videoview_extends.h(cpp): 

		将VideoView类绑定到lua

proj.android/src/cn/sharedream/game/VideoView.java
		
		android 原生视频播放器实现, 播放完毕回调native callback

proj.android/jni/VideoViewAndroidImp.cpp

		android实现, 通过jni调用 VideoView.java 的播放方法, 并实现native callback

proj.ios_mac/ios/VideoViewIOSImp.h
proj.ios_mac/ios/VideoViewIOSImp.mm

		ios实现, 通过 MPMoviePlayerController 进行播放

cocos2dx_videoview_extends's People

Contributors

pangliang avatar

Watchers

 avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.