Last active
August 10, 2022 14:39
-
-
Save senaev/93df44fe672061c8d89376b232e935c6 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| ya.videoAd | |
| .loadModule('AdLoader') | |
| // 1) Создаем экземпляр AdLoader с рекламными параметрами | |
| .then(function(module) { | |
| return module.AdLoader.create( | |
| { | |
| adBreakType: 'preroll', | |
| vastUrl: 'https://wink.sldkfjlksdfj', | |
| vast: '<VAST>.....</VAST>', | |
| }, | |
| ); | |
| }) | |
| // 2) Загружаем рекламу | |
| .then(function(adLoader) { | |
| return adLoader.loadAd(); | |
| }) | |
| // 3) Предзагружаем рекламу | |
| // Этот пункт пропускается, если рекламу необходимо запустить сразу | |
| .then(function(adStore) { | |
| // Запускаем предзагрузку | |
| return adStore.preload({ | |
| videoSlot: video, | |
| desiredBitrate: 1000, | |
| }) | |
| .then(function() { | |
| return adStore; | |
| }) | |
| .catch(function() { | |
| // Игнорируем, если в предзагрузке что-то пошло не так. | |
| // Не является блокером для проигрывания | |
| return adStore; | |
| }); | |
| }) | |
| // 4) Запускаем рекламу | |
| .then(function(adStore) { | |
| // Создаем контроллер воспроизведения | |
| const adPlaybackController = adStore.createPlaybackController(video, slot); | |
| // Подписываемся на событие окончания рекламы | |
| adPlaybackController.subscribe('AdStopped', function() { | |
| console.log('Ad stopped playing'); | |
| }); | |
| // Запускаем проигрывание рекламы | |
| adPlaybackController.playAd(); | |
| }) | |
| // Если что-то пошло не так, логируем ошибку в консоль | |
| .catch(function(error) { | |
| console.error(error); | |
| }); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment