技术标签: cocos2d-x Cocos2d-x windows
#include "VLCPlayer.h"
USING_NS_CC;
void *lock(void *data, void **p_pixels)
{
auto player = static_cast
(data);
*p_pixels = player->m_videobuf;
return NULL;
}
void unlock(void *data, void *id, void *const *p_pixels)
{
assert(id == NULL);
}
void display(void *data, void *id)
{
auto player = static_cast
(data);
player->m_readyToShow = true;
assert(id == NULL);
}
void endReached(const struct libvlc_event_t *event, void *data)
{
if (libvlc_MediaPlayerEndReached == event->type)
{
VLCPlayer *self = (VLCPlayer *)data;
self->m_isEndReached = true;
}
}
VLCPlayer::~VLCPlayer()
{
libvlc_media_player_stop(vlc_player);
libvlc_media_player_release(vlc_player);
libvlc_release(vlc);
free(m_videobuf);
}
VLCPlayer* VLCPlayer::create(Size size)
{
auto player = new VLCPlayer;
if (player && player->init(size)) {
player->autorelease();
} else {
CC_SAFE_DELETE(player);
}
return player;
}
bool VLCPlayer::init(Size &size)
{
vlc = libvlc_new(0, NULL);
vlc_player = libvlc_media_player_new(vlc);
width = size.width;
height = size.height;
m_videobuf = (char *)malloc((width * height) << 2);
memset(m_videobuf, 0, (width * height) << 2);
libvlc_video_set_callbacks(vlc_player, lock, unlock, display, this);
libvlc_video_set_format(vlc_player, "RGBA", width, height, width << 2);
libvlc_event_attach(libvlc_media_player_event_manager(vlc_player),
libvlc_MediaPlayerEndReached,
endReached,
(void *)this);
Texture2D *texture = new Texture2D();
texture->initWithData(m_videobuf,
(width * height) << 2,
Texture2D::PixelFormat::RGBA8888,
width, height, size);
texture->autorelease();
initWithTexture(texture);
scheduleUpdate();
return true;
}
void VLCPlayer::o_play(std::string &path, bool repeat)
{
m_isEndReached = false;
m_curMedia = path;
m_repeat = repeat;
m_readyToShow = false;
libvlc_media_t *media = libvlc_media_new_path(vlc, path.c_str());
libvlc_media_player_set_media(vlc_player, media);
libvlc_media_release(media);
libvlc_media_player_play(vlc_player);
}
void VLCPlayer::o_stop(void) { libvlc_media_player_stop(vlc_player); }
void VLCPlayer::o_resume(void) { libvlc_media_player_set_pause(vlc_player, 0); }
void VLCPlayer::o_pause(void) { libvlc_media_player_pause(vlc_player); }
bool VLCPlayer::isPlaying(void) { return (1 == libvlc_media_player_is_playing(vlc_player)) ? true : false; }
bool VLCPlayer::isEndReached() { return m_isEndReached; }
void VLCPlayer::draw(Renderer *renderer, const Mat4 &transform, uint32_t flags)
{
_insideBounds = (flags & FLAGS_TRANSFORM_DIRTY) ? renderer->checkVisibility(transform, _contentSize) : _insideBounds;
if(_insideBounds)
{
if (m_readyToShow) {
m_readyToShow = false;
Texture2D *texture = new Texture2D();
texture->initWithData(m_videobuf,
(width * height) << 2,
Texture2D::PixelFormat::RGBA8888,
width, height, Size(width, height));
texture->autorelease();
setTexture(texture);
}
_quadCommand.init(_globalZOrder, _texture->getName(), getGLProgramState(), _blendFunc, &_quad, 1, transform);
renderer->addCommand(&_quadCommand);
#if CC_SPRITE_DEBUG_DRAW
_debugDrawNode->clear();
Vec2 vertices[4] = {
Vec2( _quad.bl.vertices.x, _quad.bl.vertices.y ),
Vec2( _quad.br.vertices.x, _quad.br.vertices.y ),
Vec2( _quad.tr.vertices.x, _quad.tr.vertices.y ),
Vec2( _quad.tl.vertices.x, _quad.tl.vertices.y ),
};
_debugDrawNode->drawPoly(vertices, 4, true, Color4F(1.0, 1.0, 1.0, 1.0));
#endif //CC_SPRITE_DEBUG_DRAW
}
}
void VLCPlayer::update(float dt)
{
if (m_repeat && isEndReached()) {
o_play(m_curMedia);
}
}
#ifndef __MOVIEPLAYER_H__
#define __MOVIEPLAYER_H__
#include "vlc/vlc.h"
#include "cocos2d.h"
class VLCPlayer : public cocos2d::Sprite
{
public:
~VLCPlayer();
static VLCPlayer* create(cocos2d::Size size);
bool init(cocos2d::Size &size);
void o_play(std::string &path, bool repeat = true);
inline void o_stop(void);
inline void o_pause(void);
inline void o_resume(void);
inline bool isPlaying(void);
inline bool isEndReached();
virtual void draw(cocos2d::Renderer *renderer, const cocos2d::Mat4 &transform, uint32_t flags) override;
virtual void update(float dt) override;
friend void endReached(const struct libvlc_event_t *event, void *data);
friend void *lock(void *data, void **p_pixels);
friend void unlock(void *data, void *id, void *const *p_pixels);
friend void display(void *data, void *id);
private:
libvlc_instance_t *vlc;
libvlc_media_player_t *vlc_player;
unsigned int width;
unsigned int height
char *m_videobuf;
bool m_isEndReached;
std::string m_curMedia;
bool m_repeat;
bool m_readyToShow;
};
#endif
文章浏览阅读3.2k次,点赞3次,收藏23次。FTP(File Transfer Protocol,文件传输协议) 是 TCP/IP 协议组中的协议之一。FTP协议包括两个组成部分,其一为FTP服务器,其二为FTP客户端。其中FTP服务器用来存储文件,用户可以使用FTP客户端通过FTP协议访问位于FTP服务器上的资源。在开发网站的时候,通常利用FTP协议把网页或程序传到Web服务器上。此外,由于FTP传输效率非常高,在网络上传输大的文件时,..._linux 下c语言开发ftp下载工具
文章浏览阅读3.5k次,点赞5次,收藏30次。对于使用xpath()之前的文档格式化问题,可能不同的人,会遇到不一样的情况,但是基本上只要搞懂了lxml.etree.HTML(),lxml.etree.fromstring()和lxml.etree.tostring()这三者之间的区别和联系,那么文档格式化这一步一定不会有问题……_html.fromstring()含义
文章浏览阅读2k次。前言Android从API19引入了Transition过渡动画框架,它通过场景Scene概念来表述动画的关键帧,只要提供了开始和结束场景的内容就会自动做动画。过渡动画其实是对属性动画的一种封装,它能够一次对多个对象做动画而不需要特别复杂的配置。除此之外Activity之间的切换效果也可以使用过渡动画来实现。基础使用首先需要定义Scene也就是场景对象,场景其实就是某个事件点所有的..._gradentdrawable过渡
文章浏览阅读4.7k次。Edit_BIOS_Setting_Interface簡介H2OUVE是個可透過command的方式修改BIOS設定的工具,我們利用Python3撰寫一個簡易的介面,透過H2OUVE去修改BIOS的設定,省去使用者一一下指令並修改設定檔的麻煩。當多台server需套用同一個BIOS設定時,只要先針對一台電腦修改所需的BIOS設定,匯出設定檔後,即可透過deploy kit執行這個程式,讓多台ser..._h2ouve
文章浏览阅读124次。用户体验或更准确地说,电子商务用户体验(UX)是所有UI的重要方面,在处理电子商务应用程序时是必需的。当前,电子商务业务变得越来越有竞争力,各种各样的选择使客户忠诚度成为无可挑剔的现象。UX主要是指用户在操作电子商务网站时的体验。UX封装了用户在经营电子商务商店时所经历的一系列印象,包括可访问性,便利性,满意度等。拥有“好”用户体验是指用户可以高效,愉快地满足其需求的情况。此外,用户体验优化与转化化不同。尽管UX优化的重点是满意度,可用性和将其推荐给朋友的热情等指标,但其他形式的优化却着眼于提高
文章浏览阅读3.4k次,点赞5次,收藏44次。你好你好#include <iostream>using namespace std;int main(int argc, char* argv[]){ return 0;}_error: cannot launch node of type [cartographer_ros/cartographer_node]: cart
文章浏览阅读685次。rust对象封装学习笔记_rust 封装
文章浏览阅读4.6k次,点赞4次,收藏49次。此功能为了使过流时进行单拍电流进行封波设定,实现逐波限流 DAC->COMP->DCEVT->TZ.CBC(1)Comp 设定如下:AIO->COMPGpioCtrlRegs.AIOMUX1.bit.AIO2 = 0; // Configure AIO2 for CMP1A (analog input) operationComp1Regs.COMPCTL.bit.SYNCSEL = 1; // Sync with SYSCLK / use Qualif._dsp逐波限流
文章浏览阅读1k次。 1. IELTS 中文通常译作“雅思”,是前往英联邦国家留学或移民参加的一种英语水平考试。考试内容分移民类(G类)和学术类(A类),包括听、说、读、写四部分。G类与A类只在阅读和写作两个单项上有区别,考试形式为笔试,满分为9分,中国学生的成绩集中于4-7分之间。英语全称: International English Language Testing System 考试时间: 16_哪类考试单词到了国外贴合日常使用
文章浏览阅读3.8w次,点赞146次,收藏735次。map常用操作详细讲解_c++ map用法
文章浏览阅读3.5k次。本风格源自MinimalZen风格修改,存为Minimal.eetheme,在EmEditor导入后选中即可。工具 => 所有配置属性 => 显示 => 主题 => 导入 => 是否移除旧主题,选“否” => 下来选择 Minimal 主题 => 确定[Minimal]MaxFind=3Normal=#a9b7c6,#2b2b2b,normal..._emeditor主题
文章浏览阅读8k次,点赞5次,收藏6次。问:C++中四个点代表什么意思? 答: 表示类的成员。(你说的是两个冒号“:”吧) 如类CA中有成员int a; 则:CA::a表示CA类中的成员a; 举个例子: class CA { int a; int b(); }; 那么:函数int b();的定义就必须是这样的: int CA::b() { //… }..._c++四个点什么意思