# 비디오 믹스 광고

## 1. 광고 요청

loadVideoMix API를 호출하여 비디오 믹스광고를 요청합니다.

```dart
AdPopcornSSP.loadVideoMix('your_app_key', 'your_placement_id');
```

## 2. 광고 노출

비디오 믹스광고가 정상적으로 로딩 완료 된 후, 광고 노출을 하고자 하는 시점에 showVideoMix API를 호출합니다.

```dart
AdPopcornSSP.showVideoMix('your_app_key', 'your_placement_id');
```

## 3. 이벤트 연동

광고 요청, 노출에 대한 결과 이벤트를 받는 설정을 진행할 수 있습니다. 원하는 이벤트만 연동하여 사용하면 됩니다. 해당 이벤트는 초기화 시, 등록한 event Listener로 넘어옵니다.

* **(비디오 믹스) 지원되는 이벤트**

| Event                                                                                                           | 설명               |
| --------------------------------------------------------------------------------------------------------------- | ---------------- |
| <p><strong>OnVideoMixAdLoaded</strong><br>(- placementId)</p>                                                   | 비디오 믹스 광고 로드 성공  |
| <p><strong>OnVideoMixAdLoadFailed</strong><br>(- placementId, errorCode)</p>                                    | 비디오 믹스 광고 로드 실패  |
| <p><strong>OnVideoMixAdOpened</strong><br>(- placementId)</p>                                                   | 비디오 믹스 광고 노출 성공  |
| <p><strong>OnVideoMixAdOpenFailed</strong><br>(- placementId)</p>                                               | 비디오 믹스  광고 노출 실패 |
| <p><strong>OnVideoMixPlayCompleted</strong><br>(- placementId, adNetworkNo, completed)</p>                      | 비디오 믹스 광고 재생 완료  |
| <p><strong>OnVideoMixAdClosed</strong><br>(- placementId<br> - campaignType : 2(전면), 4(리워드 비디오), 6(전면 비디오))</p> | 비디오 믹스 광고 닫기     |

## 4. 샘플 코드

```js
const AdPopcornSSP = require('AdPopcornSSPPlugin');

cc.Class({
    extends: cc.Component,
    
    onLoad() {
        const ANDROID_APP_KEY = 'your_android_app_key';
        const IOS_APP_KEY = 'your_android_ios_key';
        
        const currentAppKey = cc.sys.os === cc.sys.OS_IOS ? IOS_APP_KEY : ANDROID_APP_KEY;
        if (cc.sys.os === cc.sys.OS_ANDROID || cc.sys.os === cc.sys.OS_IOS) {
            AdPopcornSSP.init(currentAppKey, (event, params) => this._onAdEvent(event, params));
            AdPopcornSSP.setLogEnable(true);
        }
    },
    _loadAds() {
        const ANDROID_APP_KEY = 'your_android_app_key';
        const IOS_APP_KEY = 'your_android_ios_key';
        
        if (cc.sys.os === cc.sys.OS_ANDROID) {
            AdPopcornSSP.loadVideoMix(ANDROID_APP_KEY, 'placement_id');
        } else if (cc.sys.os === cc.sys.OS_IOS) {
            AdPopcornSSP.loadVideoMix(IOS_APP_KEY, 'placement_id');
        }
    },
    _onAdEvent(event, params) {
        if (event === "AdPopcornSSPSDKDidInitialize") {
            this._loadAds();
        }
        else if(event === "OnVideoMixAdLoaded"){
            if (cc.sys.os === cc.sys.OS_ANDROID) {
                AdPopcornSSP.showVideoMix(ANDROID_APP_KEY, 'placement_id');
            } else if (cc.sys.os === cc.sys.OS_IOS) {
                AdPopcornSSP.showVideoMix(IOS_APP_KEY, 'placement_id');
            }
        }        
    },
});
```


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://adpopcornssp.gitbook.io/ssp-sdk/sdk/cocoscreator/undefined-5.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
