Pokračující monopolizace světa PC: kdo přijde další?

27. 9. 2024
Doba čtení: 7 minut

Sdílet

Saab 35 Draken
Autor: Christer Eklund, podle licence: CC BY-SA 4.0
Saab 35 Draken
Ve světě PC máme jediného výrobce CPU, který stojí za řeč a jediného výrobce GPU, který dominuje trhu velkých hráčských karet. Křečovitě se drží jediný správný OS, zatímco jediný správný browser si poklidně kraluje.

Myšlenka stará jako standard IBM PC samotný se neustále vrací. Tentokrát však ve velmi zvláštní variantě. Byly doby, kdy byl svět poklidně nudný, tedy zcela monopolistický. Světu běžných uživatelů vládla platforma Wintel (Windows + Intel), běželo se na Windows, hry se hrály tamtéž, internetem se brousilo v Internet Exploreru a ostatně hudba se přehrávala ve Winampu, filmy v Media Playeru 6.4, kódovalo se do DivXu a MP3, fotky se řešily v („kradeném“) Photoshopu a tak dále. O Microsoft Office se jistě netřeba zmiňovat.

Věci dokonce došly v síle monopolu tak daleko, že Microsoftu hrozilo rozdělení firmy. Ale jistota byla jedna: v x86 serverech byly Intely (později vysloveně Xeony), herní grafika se primárně odehrávala na 3Dfx Voodoo, poté GeForce a na opravdový zvukový scénicky prožitek ve hrách byl potřeba Sound Blaster Live! (vykřičník jest součástí názvu).

Některé monopoly stále žijí

Možná už si tolik nevzpomeneme, ostatně současné mladé generaci to bude připadat divné, ale byly doby, kdy se rozlišovaly „Amigácké hry“, “písíčkové hry“ a „konzolové hry“. Nemnoho jich bylo na všech platformách, přičemž po řadu let byla tou primární platformou ta jménem Wintel.

Přes všechny snahy se Windows co do hraní her stále daří. Máme tu samozřejmě Steam a Proton, takže hraní na Linuxu dnes typicky funguje (dodnes to považuji za naprostý zázrak). Navíc tvůrci enginů se pomalu stávali multiplatformními, takže prakticky vše v Unity či Unrealu může stejně dobře běžet na Playstationech (tedy „FreeBSD“) jako na Windows. Ale Windows jsou stále zde a na Linuxu si těžko hry užijeme se vším, co jim AMD a Nvidia servírují na Windows, tedy věci jako DLSS, FSR atd.

On by býval i nadále existoval monopol Direct3D, kdyby AMD nepřišla s geniálním API Mantle, pardon, Vulkan. Možnost hrát nové windowsové hry na Linuxu není ani tak dílem tůvrců enginů, her či Microsoftu, je dána primárně tím, že Vulkan a Direct3D 12 jsou si dostatečně podobná, „železu blízká“ API, a tak Steam Proton má jednodušší práci než Wine před 20 lety. Zde vlastně monopol nemizí, jen je dána možnost se mu vyhnout, pokud se člověk smíří s omezeními (již zmíněné DLSS apod.).

Jiné monopoly pomalu hynou

Situace Microsoft Office je mírně ošemetnější. A nemůže za ni ani tak LibreOffice, jako spíše systémy typu Google Dokumenty, které ostatně přiměly Microsoft za prvé zlevnit Office a za druhé vyvíjet Office 365. Vzpomínám doby kolem poloviny 90. let, kdy výplata byla cca dva tisíce Kč a balík Microsoft Office stál 15 tisíc Kč. Dnes je výplata spíše 40 tisíc Kč a Office 365 stojí pár šupů (na rok, pro celou rodinu). Ve výsledku je mnohonásobně levnější a kdo ví, zdali by si bez toho svůj stále-jakž-takž monopol podržel.

AMD nutno přiznat, že se jí monopol Nvidie podařilo značně rozbourat. Ostatně Radeony jsou srdcem už více generací konzolí, poslední GeForce byla v Playstation 3, ve stejné době jako Radeon v Xboxu 360, ale to jsou konzole, co šly na trh před téměř 20 lety. Nicméně na desktopech, dle posledních výsledků, má Nvidia stále drtivý podíl, navíc stále rostoucí. Intel už je mimo, jeho podíl je hluboce pod 1% hranicí, a tak rostoucí Nvidia opět ukusuje jen Radeonům, aktuálně drží 88 % trhu desktopových grafických karet. A to jsou její karty dražší.

Připomeňme, že Nvidia to zkoušela a zkouší i v ARMech, její řada Tegra kdysi vypadala jako blízká momentu zlomu, proniknutí na širší trhy, ale nepodařilo se jí prolomit pozice hráčů typu Samsung, Qualcomm, Mediatek.

Každopádně zhynul monopolista největší, ten, který se nebál vynucovat si na obchodních partnerech tajné zákazy nákupů u konkurenční AMD v době, kdy měla lepší produkty než on: Intel. Procesorový gigant už ztratil desktopy – definitivním hřebíčkem do rakve byla vadná výroba 13. a 14. generace Core, ke které se čelem nepostavil. Notebooky také pomalu ztrácí, ale hlavně už ztratil servery a superpočítače. Samozřejmě mu stále dobíhají dlouhodobě nasmlouvané zakázky, včetně superpočítače (Aurora), ale jinak jsou to samé AMD EPYC s GPU Nvidia či GPU (Radeon) Instinct, tu a tam se „vyloupne“ nějaký ten IBM POWER či ARM.

Monopol Windows mimochodem dávno skončil, stále více lidí používá jako primární platformu telefon či tablet (Android, iOS) či něco od Apple (nejlevnější Mac mini vyjde na 17 490 Kč). Windows nejsou na serverech, telefonech, televizorech. Jsou jen na desktopech a noteboocích. I sám Microsoft ve svých cloudech provozuje Linux a jeho vývojáři svého času doporučovali pro web Google Chrome místo Microsoft Edge.

Specifikum jménem IBM PC

Oprosťme se ale od jiných platforem a podívejme se čistě na domácí počítače tak, jak je vymysleli na přelomu 70. a 80. let v IBM. Zde monopolizace tedy stále existuje. naprostá většina nových desktopů a notebooků je dodávána s Windows. A pokud se uživateli nelíbí EULA, má buď velmi omezený výběr, nebo přímo smůlu.

Stále více a více herních strojů – dnes už bych si dovolil říci drtivá většina těch postavených rozumnými staviteli a firmami – staví na AMD Ryzenech. Je sice hezké, že v nejmenovaném e-shopu máme dnes ve výhodné slevové akci Core i9–14900K, ale to koupí jen sebevrah, bez ohledu na slevu.

No a konečně stále více a více herních PC prostě spoléhá na dekádami osvědčené řešení jménem GeForce. Na první pohled by se mohlo zdát, že Nvidia se přeci jen umoudřila. Nejlevnější Radeon poslední generace, model RX 7600 8GB se dnes pohybuje kolem 6900 Kč, zatímco nejlevnější GeForce poslední generace, model RTX 4060 8GB, kolem 7400 Kč, ale zatímco Radeon dává v single-precision výkon 14,09/21,75 TFLOPS, GeForce jen 11,2/15,1 TFLOPS, tedy za 107 % ceny člověk dostane papírově ~75 % výkonu. Přesto na každý prodaný Radeon připadá více než sedm prodaných GeForce.

Logika monopolu

Bohužel doba je příliš složitá, komplexní, než aby bylo možné zažívat časy, kdy v daném segmentu nabízely své výroby desítky až stovky firem.

Auta, zejména elektro, jsou dnes příliš komplexní. V Evropě je minimum ryze národních výrobců. Vlastně nula. Škodovka je součástí většího celku, cokoli z balíku TPCA taktéž a jednotlivé značky sdílejí společné platformy, know-how. A i tak mají problém konkurovat jak americké značce Tesla, tak záplavě čínských výrobců.

Zatímco stíhaček první generace chrlila každá průmyslová země světa spousty, na třetí a čtvrté generaci už se trh zužoval a zbyli v podstatě jen Američané, Sověti, Francouzi a Švédové (čest všem výjimkám). Evropa se pak spojovala a vznikl třeba Eurofighter Typhoon. Jiní pak využívali spolupráci s velkými, třeba Jihokorejci a Japonci. A ještě užší výběr je v generaci páté, kde už nenajdeme nástupce Raffale ani Gripenu, v podstatě se svět zúžil jen na F-22 + F35, Su-57 (pokud jej lze považovat za stealth a reálný model krom pár předváděcích strojů), Chengdu J-20 (vzniklé však díky brutální průmyslové špionáži Číny v projektech F-22 a F-35). A když vzpomeneme, že F-22 se neexportuje, tak kdo chce v západním světě vybírat novou víceúčelovou stíhačku 5. generace pro svou zemi, vybírá z faktického monopolu jediného stroje: Lockheed Martin F-35 Lightning II.

Stejné je to třeba se sportovními hodinkami, kde pro změnu onen ne-zcela-monopol plyne z povahy věci, kdy pár firem drží různé know-how dané desítkami let v oboru (Garmin s GPS, Polar se snímači, …) a vedle značek jako Coros a Suunto už tento „klub vyvolených“ vedle neopomenutelné pozice hodinek Apple úspěšně narušují prakticky jen čínské značky, které se ke svými stále lepším přístrojům dopracovávají buď průmyslovou špionáží a reverzním inženýrstvím, nebo prostým mírným pokrokem či nákupem tradičního výrobce (a je jedno, jestli je to koupě finského Suunta nebo švédské automobilky Volvo)- ať už jde o Amazfit, Huawei či Xiaomi. Nesmíme samozřejmě vynechat též stíhající Samsung. Nicméně ani v tomto segmentu nejde o desítky značek a platí, že zákazník si rád až nereálně připlatí za značku, pověst, dojem kvality, vlastní emoce z koupě – jedno, zdali jde o iPhone, nebo Garmin Fenix 8.

Monopol v IT světě je v hardwarové oblasti logický. Málokdo má desítky let rozvíjené know-how, aby předstihl tahouny trhu. Přesvědčil se o tom Intel se svými GPU, kdy ani navzdory olbřímím investicím nedokázal ani nyní s kartami Arc prorazit. Vlastně ani paběrkovat. Přesvědčil se o tom Microsoft, který navzdory koupi mobilní divize Nokie a předchozímu dominantnímu postavení platformy Windows CE/Mobile 6.x nedokázal uspět na poli chytrých telefonů.

linux_sprava_tip

Nečekejme, že bude více výrobců procesorů než Intel, AMD a skvadra armových (Qualcomm, Samsung, Mediatek, Nvidia, Apple, plus rezerva pro pár čínských) či možná, možná IBM s POWER. Nečekejme, že by Linux někdy v přímém souboji porazil Windowsy. To spíš se Windows změní v linuxový systém (tvrdím to už nějakých 15 let). Nečekejme, že by někdo mohl předstihnout Nvidii, dokud je Jen-Hsun u kormidla. Nečekejme, že by někdo urval tržní podíl Garminu pro sebe. Na takové radikální změny je potřeba zcela radikální otočení kormidlem, které se povede jen zcela výjimečně. Povedlo se Microsoftu s DOS/Windows. Povedlo se Googlu s vyhledávačem a Chrome. Povedlo se YouTube. Povedlo se Facebooku. Povedlo se TikToku. Povedlo se Applu s iPody, iPhony, iPady, Mac mini. Povedlo se Valve se Steamem. Povedlo se Nvidii s Rivou 128, GeForce 256, Quadro, Tesla, GeForce 8800 GTX + CUDA, RTX.Povedlo se OpenAI s GPT. Povedlo se Tesle s elektroauty. Povedlo se SpaceX s Falcon 9. Povedlo se SpaceX se Starlinky. Povedlo se Netflixu s online distribucí.

Povedlo se Linusovi s Linuxem a Gitem. Komu dalšímu se povede?

Autor článku

Příznivec open-source rád píšící i o ne-IT tématech. Odpůrce softwarových patentů a omezování občanských svobod ve prospěch korporací.

'; document.getElementById('preroll-iframe').onload = function () { setupIframe(); } prerollContainer = document.getElementsByClassName('preroll-container-iframe')[0]; } function setupIframe() { prerollDocument = document.getElementById('preroll-iframe').contentWindow.document; let el = prerollDocument.createElement('style'); prerollDocument.head.appendChild(el); el.innerText = "#adContainer>div:nth-of-type(1),#adContainer>div:nth-of-type(1) > iframe { width: 99% !important;height: 99% !important;max-width: 100%;}#videoContent,body{ width:100vw;height:100vh}body{ font-family:'Helvetica Neue',Arial,sans-serif}#videoContent{ overflow:hidden;background:#000}#adMuteBtn{ width:35px;height:35px;border:0;background:0 0;display:none;position:absolute;fill:rgba(230,230,230,1);bottom:20px;right:25px}"; videoContent = prerollDocument.getElementById('contentElement'); videoContent.style.display = 'none'; videoContent.volume = 1; videoContent.muted = false; const playPromise = videoContent.play(); if (playPromise !== undefined) { playPromise.then(function () { console.log('PREROLL sound allowed'); // setUpIMA(true); videoContent.volume = 1; videoContent.muted = false; setUpIMA(); }).catch(function () { console.log('PREROLL sound forbidden'); videoContent.volume = 0; videoContent.muted = true; setUpIMA(); }); } } function setupDimensions() { prerollWidth = Math.min(iinfoPrerollPosition.offsetWidth, 480); prerollHeight = Math.min(iinfoPrerollPosition.offsetHeight, 320); } function setUpIMA() { google.ima.settings.setDisableCustomPlaybackForIOS10Plus(true); google.ima.settings.setLocale('cs'); google.ima.settings.setNumRedirects(10); // Create the ad display container. createAdDisplayContainer(); // Create ads loader. adsLoader = new google.ima.AdsLoader(adDisplayContainer); // Listen and respond to ads loaded and error events. adsLoader.addEventListener( google.ima.AdsManagerLoadedEvent.Type.ADS_MANAGER_LOADED, onAdsManagerLoaded, false); adsLoader.addEventListener( google.ima.AdErrorEvent.Type.AD_ERROR, onAdError, false); // An event listener to tell the SDK that our content video // is completed so the SDK can play any post-roll ads. const contentEndedListener = function () { adsLoader.contentComplete(); }; videoContent.onended = contentEndedListener; // Request video ads. const adsRequest = new google.ima.AdsRequest(); adsRequest.adTagUrl = iinfoVastUrls[iinfoVastUrlIndex]; console.log('Preroll advert: ' + iinfoVastUrls[iinfoVastUrlIndex]); videoContent.muted = false; videoContent.volume = 1; // Specify the linear and nonlinear slot sizes. This helps the SDK to // select the correct creative if multiple are returned. // adsRequest.linearAdSlotWidth = prerollWidth; // adsRequest.linearAdSlotHeight = prerollHeight; adsRequest.nonLinearAdSlotWidth = 0; adsRequest.nonLinearAdSlotHeight = 0; adsLoader.requestAds(adsRequest); } function createAdDisplayContainer() { // We assume the adContainer is the DOM id of the element that will house // the ads. prerollDocument.getElementById('videoContent').style.display = 'none'; adDisplayContainer = new google.ima.AdDisplayContainer( prerollDocument.getElementById('adContainer'), videoContent); } function unmutePrerollAdvert() { adVolume = !adVolume; if (adVolume) { adsManager.setVolume(0.3); prerollDocument.getElementById('adMuteBtn').innerHTML = ''; } else { adsManager.setVolume(0); prerollDocument.getElementById('adMuteBtn').innerHTML = ''; } } function onAdsManagerLoaded(adsManagerLoadedEvent) { // Get the ads manager. const adsRenderingSettings = new google.ima.AdsRenderingSettings(); adsRenderingSettings.restoreCustomPlaybackStateOnAdBreakComplete = true; adsRenderingSettings.loadVideoTimeout = 12000; // videoContent should be set to the content video element. adsManager = adsManagerLoadedEvent.getAdsManager(videoContent, adsRenderingSettings); // Add listeners to the required events. adsManager.addEventListener(google.ima.AdErrorEvent.Type.AD_ERROR, onAdError); adsManager.addEventListener( google.ima.AdEvent.Type.CONTENT_PAUSE_REQUESTED, onContentPauseRequested); adsManager.addEventListener( google.ima.AdEvent.Type.CONTENT_RESUME_REQUESTED, onContentResumeRequested); adsManager.addEventListener( google.ima.AdEvent.Type.ALL_ADS_COMPLETED, onAdEvent); // Listen to any additional events, if necessary. adsManager.addEventListener(google.ima.AdEvent.Type.LOADED, onAdEvent); adsManager.addEventListener(google.ima.AdEvent.Type.STARTED, onAdEvent); adsManager.addEventListener(google.ima.AdEvent.Type.COMPLETE, onAdEvent); playAds(); } function playAds() { // Initialize the container. Must be done through a user action on mobile // devices. videoContent.load(); adDisplayContainer.initialize(); // setupDimensions(); try { // Initialize the ads manager. Ad rules playlist will start at this time. adsManager.init(1920, 1080, google.ima.ViewMode.NORMAL); // Call play to start showing the ad. Single video and overlay ads will // start at this time; the call will be ignored for ad rules. adsManager.start(); // window.addEventListener('resize', function (event) { // if (adsManager) { // setupDimensions(); // adsManager.resize(prerollWidth, prerollHeight, google.ima.ViewMode.NORMAL); // } // }); } catch (adError) { // An error may be thrown if there was a problem with the VAST response. // videoContent.play(); } } function onAdEvent(adEvent) { const ad = adEvent.getAd(); console.log('Preroll event: ' + adEvent.type); switch (adEvent.type) { case google.ima.AdEvent.Type.LOADED: if (!ad.isLinear()) { videoContent.play(); } prerollDocument.getElementById('adContainer').style.width = '100%'; prerollDocument.getElementById('adContainer').style.maxWidth = '640px'; prerollDocument.getElementById('adContainer').style.height = '360px'; break; case google.ima.AdEvent.Type.STARTED: window.addEventListener('scroll', onActiveView); if (ad.isLinear()) { intervalTimer = setInterval( function () { // Example: const remainingTime = adsManager.getRemainingTime(); // adsManager.pause(); }, 300); // every 300ms } prerollDocument.getElementById('adMuteBtn').style.display = 'block'; break; case google.ima.AdEvent.Type.ALL_ADS_COMPLETED: if (ad.isLinear()) { clearInterval(intervalTimer); } if (prerollLastError === 303) { playYtVideo(); } break; case google.ima.AdEvent.Type.COMPLETE: if (ad.isLinear()) { clearInterval(intervalTimer); } playYtVideo(); break; } } function onAdError(adErrorEvent) { console.log(adErrorEvent.getError()); prerollLastError = adErrorEvent.getError().getErrorCode(); if (!loadNext()) { playYtVideo(); } } function loadNext() { iinfoVastUrlIndex++; if (iinfoVastUrlIndex < iinfoVastUrls.length) { iinfoPrerollPosition.remove(); playPrerollAd(); } else { return false; } adVolume = 1; return true; } function onContentPauseRequested() { videoContent.pause(); } function onContentResumeRequested() { videoContent.play(); } function onActiveView() { if (prerollContainer) { const containerOffset = prerollContainer.getBoundingClientRect(); const windowHeight = window.innerHeight; if (containerOffset.top < windowHeight/1 && containerOffset.bottom > 0.0) { if (prerollPaused) { adsManager.resume(); prerollPaused = false; } return true; } else { if (!prerollPaused) { adsManager.pause(); prerollPaused = true; } } } return false; } function playYtVideo() { iinfoPrerollPosition.remove(); youtubeIframe.style.display = 'block'; youtubeIframe.src += '&autoplay=1&mute=1'; } }
'; document.getElementById('outstream-iframe').onload = function () { setupIframe(); } replayScreen = document.getElementById('iinfoOutstreamReplay'); iinfoOutstreamPosition = document.getElementById('iinfoOutstreamPosition'); outstreamContainer = document.getElementsByClassName('outstream-container')[0]; setupReplayScreen(); } function setupIframe() { outstreamDocument = document.getElementById('outstream-iframe').contentWindow.document; let el = outstreamDocument.createElement('style'); outstreamDocument.head.appendChild(el); el.innerText = "#adContainer>div:nth-of-type(1),#adContainer>div:nth-of-type(1) > iframe { width: 99% !important;height: 99% !important;max-width: 100%;}#videoContent,body{ width:100vw;height:100vh}body{ font-family:'Helvetica Neue',Arial,sans-serif}#videoContent{ overflow:hidden;background:#000}#adMuteBtn{ width:35px;height:35px;border:0;background:0 0;display:none;position:absolute;fill:rgba(230,230,230,1);bottom:-5px;right:25px}"; videoContent = outstreamDocument.getElementById('contentElement'); videoContent.style.display = 'none'; videoContent.volume = 1; videoContent.muted = false; if ( location.href.indexOf('rejstriky.finance.cz') !== -1 || location.href.indexOf('finance-rejstrik') !== -1 || location.href.indexOf('firmy.euro.cz') !== -1 || location.href.indexOf('euro-rejstrik') !== -1 || location.href.indexOf('/rejstrik/') !== -1 || location.href.indexOf('/rejstrik-firem/') !== -1) { outstreamDirectPlayed = true; soundAllowed = true; iinfoVastUrlIndex = 0; } if (!outstreamDirectPlayed) { console.log('OUTSTREAM direct'); setUpIMA(true); } else { if (soundAllowed) { const playPromise = videoContent.play(); if (playPromise !== undefined) { playPromise.then(function () { console.log('OUTSTREAM sound allowed'); setUpIMA(false); }).catch(function () { console.log('OUTSTREAM sound forbidden'); renderBanner(); }); } } else { renderBanner(); } } } function getWrapper() { let articleWrapper = document.querySelector('.rs-outstream-placeholder'); // Outstream Placeholder from RedSys manipulation if (articleWrapper && articleWrapper.style.display !== 'block') { articleWrapper.innerHTML = ""; articleWrapper.style.display = 'block'; } // Don't render OutStream on homepages if (articleWrapper === null) { if (document.querySelector('body.p-index')) { return null; } } if (articleWrapper === null) { articleWrapper = document.getElementById('iinfo-outstream'); } if (articleWrapper === null) { articleWrapper = document.querySelector('.layout-main__content .detail__article p:nth-of-type(6)'); } if (articleWrapper === null) { // Euro, Autobible, Zdravi articleWrapper = document.querySelector('.o-article .o-article__text p:nth-of-type(6)'); } if (articleWrapper === null) { articleWrapper = document.getElementById('sidebar'); } if (!articleWrapper) { console.error("Outstream wrapper of article was not found."); } return articleWrapper; } function setupDimensions() { outstreamWidth = Math.min(iinfoOutstreamPosition.offsetWidth, 480); outstreamHeight = Math.min(iinfoOutstreamPosition.offsetHeight, 320); } /** * Sets up IMA ad display container, ads loader, and makes an ad request. */ function setUpIMA(direct) { google.ima.settings.setDisableCustomPlaybackForIOS10Plus(true); google.ima.settings.setLocale('cs'); google.ima.settings.setNumRedirects(10); // Create the ad display container. createAdDisplayContainer(); // Create ads loader. adsLoader = new google.ima.AdsLoader(adDisplayContainer); // Listen and respond to ads loaded and error events. adsLoader.addEventListener( google.ima.AdsManagerLoadedEvent.Type.ADS_MANAGER_LOADED, onAdsManagerLoaded, false); adsLoader.addEventListener( google.ima.AdErrorEvent.Type.AD_ERROR, onAdError, false); // An event listener to tell the SDK that our content video // is completed so the SDK can play any post-roll ads. const contentEndedListener = function () { adsLoader.contentComplete(); }; videoContent.onended = contentEndedListener; // Request video ads. const adsRequest = new google.ima.AdsRequest(); if (direct) { adsRequest.adTagUrl = directVast; console.log('Outstream DIRECT CAMPAING advert: ' + directVast); videoContent.muted = true; videoContent.volume = 0; outstreamDirectPlayed = true; } else { adsRequest.adTagUrl = iinfoVastUrls[iinfoVastUrlIndex]; console.log('Outstream advert: ' + iinfoVastUrls[iinfoVastUrlIndex]); videoContent.muted = false; videoContent.volume = 1; } // Specify the linear and nonlinear slot sizes. This helps the SDK to // select the correct creative if multiple are returned. // adsRequest.linearAdSlotWidth = outstreamWidth; // adsRequest.linearAdSlotHeight = outstreamHeight; adsRequest.nonLinearAdSlotWidth = 0; adsRequest.nonLinearAdSlotHeight = 0; adsLoader.requestAds(adsRequest); } function setupReplayScreen() { replayScreen.addEventListener('click', function () { iinfoOutstreamPosition.remove(); iinfoVastUrlIndex = 0; outstreamInit(); }); } /** * Sets the 'adContainer' div as the IMA ad display container. */ function createAdDisplayContainer() { // We assume the adContainer is the DOM id of the element that will house // the ads. outstreamDocument.getElementById('videoContent').style.display = 'none'; adDisplayContainer = new google.ima.AdDisplayContainer( outstreamDocument.getElementById('adContainer'), videoContent); } function unmuteAdvert() { adVolume = !adVolume; if (adVolume) { adsManager.setVolume(0.3); outstreamDocument.getElementById('adMuteBtn').innerHTML = ''; } else { adsManager.setVolume(0); outstreamDocument.getElementById('adMuteBtn').innerHTML = ''; } } /** * Loads the video content and initializes IMA ad playback. */ function playAds() { // Initialize the container. Must be done through a user action on mobile // devices. videoContent.load(); adDisplayContainer.initialize(); // setupDimensions(); try { // Initialize the ads manager. Ad rules playlist will start at this time. adsManager.init(1920, 1080, google.ima.ViewMode.NORMAL); // Call play to start showing the ad. Single video and overlay ads will // start at this time; the call will be ignored for ad rules. adsManager.start(); // window.addEventListener('resize', function (event) { // if (adsManager) { // setupDimensions(); // adsManager.resize(outstreamWidth, outstreamHeight, google.ima.ViewMode.NORMAL); // } // }); } catch (adError) { // An error may be thrown if there was a problem with the VAST response. // videoContent.play(); } } /** * Handles the ad manager loading and sets ad event listeners. * @param { !google.ima.AdsManagerLoadedEvent } adsManagerLoadedEvent */ function onAdsManagerLoaded(adsManagerLoadedEvent) { // Get the ads manager. const adsRenderingSettings = new google.ima.AdsRenderingSettings(); adsRenderingSettings.restoreCustomPlaybackStateOnAdBreakComplete = true; adsRenderingSettings.loadVideoTimeout = 12000; // videoContent should be set to the content video element. adsManager = adsManagerLoadedEvent.getAdsManager(videoContent, adsRenderingSettings); // Add listeners to the required events. adsManager.addEventListener(google.ima.AdErrorEvent.Type.AD_ERROR, onAdError); adsManager.addEventListener( google.ima.AdEvent.Type.CONTENT_PAUSE_REQUESTED, onContentPauseRequested); adsManager.addEventListener( google.ima.AdEvent.Type.CONTENT_RESUME_REQUESTED, onContentResumeRequested); adsManager.addEventListener( google.ima.AdEvent.Type.ALL_ADS_COMPLETED, onAdEvent); // Listen to any additional events, if necessary. adsManager.addEventListener(google.ima.AdEvent.Type.LOADED, onAdEvent); adsManager.addEventListener(google.ima.AdEvent.Type.STARTED, onAdEvent); adsManager.addEventListener(google.ima.AdEvent.Type.COMPLETE, onAdEvent); playAds(); } /** * Handles actions taken in response to ad events. * @param { !google.ima.AdEvent } adEvent */ function onAdEvent(adEvent) { // Retrieve the ad from the event. Some events (for example, // ALL_ADS_COMPLETED) don't have ad object associated. const ad = adEvent.getAd(); console.log('Outstream event: ' + adEvent.type); switch (adEvent.type) { case google.ima.AdEvent.Type.LOADED: // This is the first event sent for an ad - it is possible to // determine whether the ad is a video ad or an overlay. if (!ad.isLinear()) { // Position AdDisplayContainer correctly for overlay. // Use ad.width and ad.height. videoContent.play(); } outstreamDocument.getElementById('adContainer').style.width = '100%'; outstreamDocument.getElementById('adContainer').style.maxWidth = '640px'; outstreamDocument.getElementById('adContainer').style.height = '360px'; break; case google.ima.AdEvent.Type.STARTED: window.addEventListener('scroll', onActiveView); // This event indicates the ad has started - the video player // can adjust the UI, for example display a pause button and // remaining time. if (ad.isLinear()) { // For a linear ad, a timer can be started to poll for // the remaining time. intervalTimer = setInterval( function () { // Example: const remainingTime = adsManager.getRemainingTime(); // adsManager.pause(); }, 300); // every 300ms } outstreamDocument.getElementById('adMuteBtn').style.display = 'block'; break; case google.ima.AdEvent.Type.ALL_ADS_COMPLETED: if (ad.isLinear()) { clearInterval(intervalTimer); } if (outstreamLastError === 303) { if (isBanner) { renderBanner(); } else { replayScreen.style.display = 'flex'; } } break; case google.ima.AdEvent.Type.COMPLETE: // This event indicates the ad has finished - the video player // can perform appropriate UI actions, such as removing the timer for // remaining time detection. if (ad.isLinear()) { clearInterval(intervalTimer); } if (isBanner) { renderBanner(); } else { replayScreen.style.display = 'flex'; } break; } } /** * Handles ad errors. * @param { !google.ima.AdErrorEvent } adErrorEvent */ function onAdError(adErrorEvent) { // Handle the error logging. console.log(adErrorEvent.getError()); outstreamLastError = adErrorEvent.getError().getErrorCode(); if (!loadNext()) { renderBanner(); } } function renderBanner() { if (isBanner) { console.log('Outstream: Render Banner'); iinfoOutstreamPosition.innerHTML = ""; iinfoOutstreamPosition.style.height = "330px"; iinfoOutstreamPosition.appendChild(bannerDiv); } else { console.log('Outstream: Banner is not set'); } } function loadNext() { iinfoVastUrlIndex++; if (iinfoVastUrlIndex < iinfoVastUrls.length) { iinfoOutstreamPosition.remove(); outstreamInit(); } else { return false; } adVolume = 1; return true; } /** * Pauses video content and sets up ad UI. */ function onContentPauseRequested() { videoContent.pause(); // This function is where you should setup UI for showing ads (for example, // display ad timer countdown, disable seeking and more.) // setupUIForAds(); } /** * Resumes video content and removes ad UI. */ function onContentResumeRequested() { videoContent.play(); // This function is where you should ensure that your UI is ready // to play content. It is the responsibility of the Publisher to // implement this function when necessary. // setupUIForContent(); } function onActiveView() { if (outstreamContainer) { const containerOffset = outstreamContainer.getBoundingClientRect(); const windowHeight = window.innerHeight; if (containerOffset.top < windowHeight/1 && containerOffset.bottom > 0.0) { if (outstreamPaused) { adsManager.resume(); outstreamPaused = false; } return true; } else { if (!outstreamPaused) { adsManager.pause(); outstreamPaused = true; } } } return false; } let outstreamInitInterval; if (typeof cpexPackage !== "undefined") { outstreamInitInterval = setInterval(tryToInitializeOutstream, 100); } else { const wrapper = getWrapper(); if (wrapper) { let outstreamInitialized = false; window.addEventListener('scroll', () => { if (!outstreamInitialized) { const containerOffset = wrapper.getBoundingClientRect(); const windowHeight = window.innerHeight; if (containerOffset.top < windowHeight / 1 && containerOffset.bottom > 0.0) { outstreamInit(); outstreamInitialized = true; } } }); } } function tryToInitializeOutstream() { const wrapper = getWrapper(); if (wrapper) { const containerOffset = wrapper.getBoundingClientRect(); const windowHeight = window.innerHeight; if (containerOffset.top < windowHeight / 1 && containerOffset.bottom > 0.0) { if (cpexPackage.adserver.displayed) { clearInterval(outstreamInitInterval); outstreamInit(); } } } else { clearInterval(outstreamInitInterval); } } }
OSZAR »