ปรับปรุงเวลาในการโหลด IMA
จัดทุกอย่างให้เป็นระเบียบอยู่เสมอด้วยคอลเล็กชัน
บันทึกและจัดหมวดหมู่เนื้อหาตามค่ากำหนดของคุณ
IMA SDK จะโหลดทรัพยากรที่ต้องพึ่งพาเพื่อขอสตรีมการแทรกโฆษณาแบบไดนามิก (DAI) วัดการมองเห็นโฆษณา และรายงานการแสดงโฆษณา การกำหนดค่า IMA ก่อนส่งคำขอสตรีมจะช่วยให้คุณมีเวลาในการโหลดทรัพยากร IMA ก่อนที่จะเล่นสตรีมได้มากที่สุด หน้านี้จะอธิบายวิธีจัดการเวลาในการโหลด IMA ในแอป
โทร ImaSdkFactory.initialize()
วิธีการนี้จะเริ่มโหลดทรัพยากร SDK ล่วงหน้าก่อนคําขอสตรีมแรกImaSdkFactory.initialize()
หากต้องการใช้ initialize()
คุณต้องมี IMA เวอร์ชัน 3.35.1 ขึ้นไป
เรียก ImaSdkFactory.initialize()
เมื่อแอปพลิเคชันเริ่มต้น หรือเรียกให้เร็วที่สุดเท่าที่โครงสร้างแอปอนุญาตในวงจรของแอปพลิเคชัน การเรียก initialize()
ใช้พารามิเตอร์ต่อไปนี้
context
: ใช้บริบทแอปพลิเคชัน ซึ่งพร้อมใช้งานเสมอตลอดอายุการใช้งานของแอปพลิเคชัน
settings
: ส่งออบเจ็กต์ ImaSdkSettings
ที่มีการตั้งค่าค่า การตั้งค่า IMA ที่ใช้ในการเรียก initialize()
ต้องเหมือนกับค่าการตั้งค่าที่ใช้ในการเรียก createAdsLoader()
IMA SDK จะใช้การตั้งค่าเหล่านี้ โดยเฉพาะการตั้งค่าภาษา สำหรับคีย์แคช เราไม่แนะนําให้ใช้ค่าทดสอบหรือค่าสมมติสําหรับการตั้งค่าที่ใช้ในinitialize()
method call เนื่องจากอาจเกิดแคชไม่พบและทำให้เวลาในการโหลดโฆษณาเพิ่มขึ้น
ใช้อินสแตนซ์ AdsLoader
ซ้ำ
เราขอแนะนำให้คุณนําAdsLoader
เดิมมาใช้ซ้ำเพื่อปรับปรุงเวลาในการโหลด IMA อินเทอร์เฟซ AdsLoader
สามารถจัดการคําขอโฆษณาหรือสตรีมหลายรายการ
หลีกเลี่ยงการสร้างอินสแตนซ์ AdsLoader
ใหม่สำหรับคำขอแต่ละรายการ การสร้างAdsLoader
อินสแตนซ์ใหม่ต้องใช้เวลาในการโหลดและใช้ทรัพยากรของอุปกรณ์เพิ่มเติม
ขอสตรีมล่วงหน้าก่อนเล่น
หากมีสิทธิ์เข้าถึงอินสแตนซ์ AdsLoader
ก่อนเริ่มเล่นสตรีม คุณก็เรียกใช้เมธอด AdsLoader.requestStream()
ได้ตั้งแต่เนิ่นๆ การเรียกใช้นี้จะเริ่มต้นการโหลดสตรีม DAI เมื่อผู้ใช้พร้อมเริ่มเล่นสตรีม ให้เรียกใช้เมธอด StreamManager.init()
เพื่อเริ่มต้นเล่นสตรีม
เนื้อหาของหน้าเว็บนี้ได้รับอนุญาตภายใต้ใบอนุญาตที่ต้องระบุที่มาของครีเอทีฟคอมมอนส์ 4.0 และตัวอย่างโค้ดได้รับอนุญาตภายใต้ใบอนุญาต Apache 2.0 เว้นแต่จะระบุไว้เป็นอย่างอื่น โปรดดูรายละเอียดที่นโยบายเว็บไซต์ Google Developers Java เป็นเครื่องหมายการค้าจดทะเบียนของ Oracle และ/หรือบริษัทในเครือ
อัปเดตล่าสุด 2025-08-21 UTC
[null,null,["อัปเดตล่าสุด 2025-08-21 UTC"],[],[],null,["# Improve IMA load time\n\nThe IMA SDK loads dependencies to request Dynamic Ad Insertion (DAI) streams,\nmeasure viewability and report ad impressions. By initializing IMA before you\nmake a stream request, you maximize the time to load IMA dependencies before\nstream playback. This page covers how to handling IMA load times in your app.\n\nCall `ImaSdkFactory.initialize()`\n---------------------------------\n\nThe\n[`ImaSdkFactory.initialize()`](/ad-manager/dynamic-ad-insertion/sdk/android/api/reference/com/google/ads/interactivemedia/v3/api/ImaSdkFactory#initialize(android.content.Context,com.google.ads.interactivemedia.v3.api.ImaSdkSettings))\nmethod starts to preload SDK resources in advance of the first stream request.\nTo use `initialize()`, you need IMA version 3.35.1 or higher.\n\nCall `ImaSdkFactory.initialize()` on application startup, or as early in the\napplication's lifecycle as your app structure allows. The `initialize()` call\ntakes the following parameters:\n\n- **`context`**: Uses the application context, which is always available during the lifecycle of the application.\n- **`settings`** : Pass the an [`ImaSdkSettings`](/ad-manager/dynamic-ad-insertion/sdk/android/api/reference/com/google/ads/interactivemedia/v3/api/ImaSdkSettings) object with its values set. The IMA settings used in the `initialize()` call must be the same as the settings values used in the `createAdsLoader()` call. The IMA SDK utilizes these settings, particularly the language setting, for cache key. We don't recommend using test or fake values for the settings used in the `initialize()` method call, as cache misses might occur and increase ad load time.\n\nReuse the `AdsLoader` instance\n------------------------------\n\nTo improve IMA load time, we recommend you reuse the same\n[`AdsLoader`](/interactive-media-ads/docs/sdks/android/client-side/api/reference/com/google/ads/interactivemedia/v3/api/AdsLoader)\ninstance. The `AdsLoader` interface can handle multiple ad or stream requests.\nAvoid creating a new `AdsLoader` instance for each request. Creating a new\n`AdsLoader` instance requires a load time, and uses additional device resources.\n\nRequest streams in advance of playback\n--------------------------------------\n\nIf you have access to the `AdsLoader` instance prior to starting stream\nplayback, you can also call the\n[`AdsLoader.requestStream()`](/ad-manager/dynamic-ad-insertion/sdk/android/api/reference/com/google/ads/interactivemedia/v3/api/AdsLoader#requestStream(com.google.ads.interactivemedia.v3.api.StreamRequest))\nmethod early. Making this call starts loading the DAI stream. When the user\nis ready to start stream playback, call the\n[`StreamManager.init()`](/ad-manager/dynamic-ad-insertion/sdk/android/api/reference/com/google/ads/interactivemedia/v3/api/BaseManager#init())\nmethod to initialize stream playback."]]