Cocos2d-3.x_视频播放(Android和iOS平台)

Cocos2d-3.x_视频播放(Android和iOS平台),第1张

概述#ifndef __HELLOWORLD_SCENE_H__#define __HELLOWORLD_SCENE_H__#include "cocos2d.h"#include "ui/CocosGUI.h"USING_NS_CC;class HelloWorld : public cocos2d::Layer{public: static cocos2d::Scen
#ifndef __HELLOWORLD_SCENE_H__#define __HELLOWORLD_SCENE_H__#include "cocos2d.h"#include "ui/CocosGUI.h"USING_NS_CC;class HelloWorld : public cocos2d::Layer{public:    static cocos2d::Scene* createScene();    virtual bool init();	// 设置视频播放时的状态的回调函数,必须加上平台判断的宏定义才能不报错#if (CC_TARGET_PLATFORM == CC_PLATFORM_ANDROID || CC_TARGET_PLATFORM == CC_PLATFORM_IOS)	voID vIDeoEventCallback(Ref* sender,cocos2d::experimental::ui::VIDeoPlayer::EventType eventType);#endif	// 设置视频播放完成时的回调函数	voID vIDeoPlayOverCallback();    CREATE_FUNC(HelloWorld);private:};#endif // __HELLOWORLD_SCENE_H__
#include "HelloWorldScene.h"Scene* HelloWorld::createScene(){    auto scene = Scene::create();    auto layer = HelloWorld::create();    scene->addChild(layer);    return scene;}bool HelloWorld::init(){    if ( !Layer::init() )    {        return false;    }    	Size visibleSize = Director::getInstance()->getVisibleSize();    Vec2 origin = Director::getInstance()->getVisibleOrigin();	auto sprite = Sprite::create("HelloWorld.png");	sprite->setposition(Vec2(visibleSize.wIDth / 2 + origin.x,visibleSize.height / 2 + origin.y));	this->addChild(sprite,0);	// 在Cocos2d-3.x中,增加了可以播放视频的API,但必须注意的是:到目前为止,只能在AndroID和iOS平台进行播放视频,如果在其他的平台,代码则会编译出错,所以需要加上平台判断的宏定义才能编译通过#if (CC_TARGET_PLATFORM == CC_PLATFORM_ANDROID || CC_TARGET_PLATFORM == CC_PLATFORM_IOS)	auto vIDeoPlayer = cocos2d::experimental::ui::VIDeoPlayer::create();	vIDeoPlayer->setContentSize(visibleSize);	vIDeoPlayer->setposition(visibleSize/2.0);	vIDeoPlayer->setfilename("vIDeo.mp4");	vIDeoPlayer->addEventListener(CC_CALLBACK_2(HelloWorld::vIDeoEventCallback,this));	vIDeoPlayer->play();	this->addChild(vIDeoPlayer);#endif    return true;}voID HelloWorld::vIDeoPlayOverCallback(){}#if (CC_TARGET_PLATFORM == CC_PLATFORM_ANDROID || CC_TARGET_PLATFORM == CC_PLATFORM_IOS)voID HelloWorld::vIDeoEventCallback(Ref* sender,cocos2d::experimental::ui::VIDeoPlayer::EventType eventType){	switch (eventType) 	{	case cocos2d::experimental::ui::VIDeoPlayer::EventType::PLAYING:		break;	case cocos2d::experimental::ui::VIDeoPlayer::EventType::PAUSED:		break;	case cocos2d::experimental::ui::VIDeoPlayer::EventType::StopPED:		break;	case cocos2d::experimental::ui::VIDeoPlayer::EventType::COMPLETED:		this->vIDeoPlayOverCallback();		break;	default:		break;	}}#endif
总结

以上是内存溢出为你收集整理的Cocos2d-3.x_视频播放(Android和iOS平台)全部内容,希望文章能够帮你解决Cocos2d-3.x_视频播放(Android和iOS平台)所遇到的程序开发问题。

如果觉得内存溢出网站内容还不错,欢迎将内存溢出网站推荐给程序员好友。

欢迎分享,转载请注明来源:内存溢出

原文地址:https://www.54852.com/web/1054195.html

(0)
打赏 微信扫一扫微信扫一扫 支付宝扫一扫支付宝扫一扫
上一篇 2022-05-25
下一篇2022-05-25

发表评论

登录后才能评论

评论列表(0条)

    保存