Put a sprite or any layer over a VideoPlayer layer?

Is it possible to add a sprite or any layer over a VideoPlayer layer?

sure, work on your z-order

Here is the sample code:

auto videoPlayer = VideoPlayer::create(); auto sprite = Sprite::create("sprite.png"); this->addChild(videoPlayer, 1); this->addChild(sprite, 2);

However, the Sprite object is rendered below the VideoLayer.

I’ll try this and get back to you

Please, please.

It is a holiday the last 3 days. I’ll try tomorrow.

Hi,

How we can add Sprite or Label above Video Layer. Zorder will not work. Always all object will render below the Video Layer.

I didn’t find direct solution for this. But some how i worked out find the alternative solution for this.

I wanted to Add Label above the Video Player. I implemented in Native method. For IOS using Objective C & For Android using Java code.

For Example: In IOS: UIVideoPlayer-ios.mm

-(void)addSkipLabel
{
     if (self.moviePlayer != nullptr)
     {
          auto view = cocos2d::Director::getInstance()->getOpenGLView();
          auto eaglview = (CCEAGLView *) view->getEAGLView();
          
          UILabel *myLabel = [[UILabel alloc]initWithFrame:CGRectMake([eaglview frame].size.width * 0.85,[eaglview frame].size.height * 0.9, 150, [eaglview frame].size.height/14)];
          [myLabel setBackgroundColor:[UIColor clearColor]];
          [myLabel setText:@"Tap to Skip"];
          [myLabel setTextColor:[UIColor whiteColor]];
          [self.moviePlayer.view addSubview:myLabel];
          [myLabel release];
     }
}

While Creating Video, I have called this function.

Regards,
Gurudath

Possible hack. Add an extra layer over the video player and then add the sprite as a child to this layer. I don’t know if that would work :stuck_out_tongue: Don’t allow touch to swallow on that layer.

1 Like

is there any result?

The way you proposed does not work as intended.

Have you ever tried this issue?

I’m sorry, I lost track of this, I’ll look at it now.

1 Like

My first attempt was:

auto centerPos = Vec2(_visibleRect.origin.x + _visibleRect.size.width / 2,_visibleRect.origin.y + _visibleRect.size.height /2);

    auto widgetSize = _widget->getContentSize();

    _videoPlayer = VideoPlayer::create();
    _videoPlayer->setPosition(centerPos);
    _videoPlayer->setAnchorPoint(Vec2::ANCHOR_MIDDLE);
    _videoPlayer->setContentSize(Size(widgetSize.width * 0.4f,widgetSize.height * 0.4f));
    _uiLayer->addChild(_videoPlayer,1);
    
    _videoPlayer->addEventListener(CC_CALLBACK_2(VideoPlayerTest::videoEventCallback, this));
    
    auto sprite = Sprite::create("Hello.png");
    sprite->setPosition(centerPos);
    _uiLayer->addChild(sprite, 2);

and this produced the results that you are seeing:
Sprite is on top of the video until it starts playing, then the video is overtop.


My second attempt was this:

auto centerPos = Vec2(_visibleRect.origin.x + _visibleRect.size.width / 2,_visibleRect.origin.y + _visibleRect.size.height /2);

    auto widgetSize = _widget->getContentSize();

    _videoPlayer = VideoPlayer::create();
    _videoPlayer->setPosition(centerPos);
    _videoPlayer->setAnchorPoint(Vec2::ANCHOR_MIDDLE);
    _videoPlayer->setContentSize(Size(widgetSize.width * 0.4f,widgetSize.height * 0.4f));
    _uiLayer->addChild(_videoPlayer,1);
    
    _videoPlayer->addEventListener(CC_CALLBACK_2(VideoPlayerTest::videoEventCallback, this));
    
    auto layer = LayerColor::create(cocos2d::Color4B(100, 100, 50, 75));
    layer->setAnchorPoint(cocos2d::Vec2(0.5, 0.5));
    layer->setContentSize(cocos2d::Size(_visibleRect.size.width / 2, _visibleRect.size.height / 2));
    layer->setPosition(centerPos);
    
    auto sprite = Sprite::create("Hello.png");
    layer->addChild(sprite,0);
    sprite->setPosition(centerPos);
    
    _uiLayer->addChild(layer, 2);

Same result.

I filed a bug for this.

Any updates to this bug fix?

this is not a bug, in the library video layer is set always on top.

If it is not a bug then how we put node over it. Is there any workaround?

It’s not a bug it is expected functionality.