ذخیره و بارگیری نشانکهای جریان آگهی، ذخیره و بارگیری نشانکهای جریان آگهی، ذخیره و بارگیری نشانکهای جریان آگهی، ذخیره و بارگیری نشانکهای جریان آگهی
با مجموعهها، منظم بمانید
ذخیره و طبقهبندی محتوا براساس اولویتهای شما.
این راهنما نحوه پیادهسازی نشانکگذاری را با استفاده از IMA DAI SDK هنگام استفاده از درج آگهی پویا (DAI) برای جریانهای ویدیویی بر اساس تقاضا (VOD) نشان میدهد. این یک پیاده سازی IMA DAI را فرض می کند، مانند آنچه در Get Started ارائه شده است.
نشانه گذاری چیست؟
نشانک گذاری توانایی ذخیره و سپس بازگشت به یک نقطه خاص در جریان محتوا است. فرض کنید کاربر پنج دقیقه محتوا را تماشا می کند، جریان ویدیو را ترک می کند و سپس به آن باز می گردد. نشانکگذاری موقعیت کاربر را در جریان ذخیره میکند تا جریان بتواند از جایی که متوقف شده است ادامه یابد و تجربهای بینظیر برای بیننده فراهم کند.
نشانه گذاری DAI در زیر کاپوت
هنگام بوکمارک کردن یک جریان DAI، باید شناسه جریان و زمان خروج کاربر از ویدیو را ضبط کنید. پس از بازگشت کاربر، جریان را دوباره درخواست کنید و زمان ذخیره شده را جستجو کنید. از آنجایی که هر نمونه از جریان درخواستی میتواند دارای وقفههای تبلیغاتی با مدت زمان متفاوت باشد، صرفهجویی در زمان پخش کار نخواهد کرد. کاری که واقعاً می خواهید انجام دهید این است که از همان زمان محتوا ادامه دهید.
روش های تبدیل به نجات
IMA DAI SDK یک جفت روش برای درخواست زمان محتوا برای یک زمان پخش جریانی معین و زمان پخش برای یک زمان محتوا ارائه می دهد. با استفاده از این روشهای تبدیل، میتوانید زمان محتوای نشانهگذاریشده را ذخیره کنید و سپس زمان پخش متناظر را در نمونه جدید جریان جستجو کنید. در اینجا این رویکرد است، از جمله پیوندی به یک برنامه نمونه که اجرای نشانهگذاری کارآمد را نشان میدهد.
ذخیره نشانک ها
هنگامی که Activity
متوقف می شود، یک نشانک ذخیره کنید.
private double bookmarkTime;
@Override
public void onPause() {
super.onPause();
double streamTime = videoPlayer.getCurrentPosition() / 1000.0; // ms to s.
bookmarkTime = streamManager.getContentTimeForStreamTime(streamTime);
}
در حال بارگیری نشانک ها
هنگام درخواست مجدد جریان، نشانک را بارگیری کنید. این بخشی از پیاده سازی رابط VideoStreamPlayer
است.
public void loadUrl(String url, List<HashMap<String, String>> subtitles) {
// Set video player's stream URL and subtitles, and play the stream.
...
// Bookmarking.
if (bookmarkTime > 0) {
double streamTime =
streamManager.getStreamTimeForContentTime(bookmarkTime);
videoPlayer.seek((long) (streamTime * 1000.0)); // s to ms.
}
}
نمونه برنامه
برای مشاهده اجرای نشانک گذاری ، برنامه Sample را دانلود کنید .
جز در مواردی که غیر از این ذکر شده باشد،محتوای این صفحه تحت مجوز Creative Commons Attribution 4.0 License است. نمونه کدها نیز دارای مجوز Apache 2.0 License است. برای اطلاع از جزئیات، به خطمشیهای سایت Google Developers مراجعه کنید. جاوا علامت تجاری ثبتشده Oracle و/یا شرکتهای وابسته به آن است.
تاریخ آخرین بهروزرسانی 2025-08-21 بهوقت ساعت هماهنگ جهانی.
[null,null,["تاریخ آخرین بهروزرسانی 2025-08-21 بهوقت ساعت هماهنگ جهانی."],[[["\u003cp\u003eThis guide explains how to implement bookmarking in video-on-demand (VOD) streams using the IMA DAI SDK for a seamless viewing experience.\u003c/p\u003e\n"],["\u003cp\u003eBookmarking involves saving the user's content time, not just stream time, to ensure accurate playback resumption.\u003c/p\u003e\n"],["\u003cp\u003eThe IMA DAI SDK provides methods to convert between stream time and content time for bookmarking purposes.\u003c/p\u003e\n"],["\u003cp\u003eDevelopers can save bookmarks when the activity is paused and load them when the stream is re-requested.\u003c/p\u003e\n"],["\u003cp\u003eA sample app demonstrating bookmarking implementation is available on GitHub.\u003c/p\u003e\n"]]],["Bookmarking in IMA DAI involves saving the user's position in a video stream for later continuation. Instead of recording the stream time, the key is to save the content time. When a user leaves, record the stream ID and convert the current stream time to content time using `getContentTimeForStreamTime()`. Upon return, re-request the stream and use `getStreamTimeForContentTime()` to find the corresponding stream time to seek to. Bookmarks are saved when the `Activity` pauses and loaded when re-requesting a stream.\n"],null,["# Save and load ad stream bookmarks\n\nThis guide shows how to implement bookmarking using the IMA DAI SDK\nwhen using Dynamic Ad Insertion (DAI) for video-on-demand (VOD) streams.\nThis assumes a working IMA DAI implementation, such as the one presented in\n\n\n[Get Started](/interactive-media-ads/docs/sdks/android/dai-quickstart).\n\n\nWhat is bookmarking?\n--------------------\n\nBookmarking is the ability to save and then return to a specific point\nin the content stream. Suppose a user watches five minutes of content,\nleaves the video stream, and then returns to it. Bookmarking saves the\nuser's position in the stream so the stream can pick up from where it\nleft off, providing a seamless experience to the viewer.\n\nDAI bookmarking under the hood\n------------------------------\n\nWhen bookmarking a DAI stream, you must record the stream id and time\nwhen the user leaves the video. When the user returns, re-request the\nstream and seek to the saved time. Since each instance of the requested\nstream can have ad breaks of different durations simply saving the stream\ntime won't work. What you really want to do is continue from the same\n**content time**.\n\nConversion methods to the rescue\n--------------------------------\n\nThe IMA DAI SDK provides a pair of methods to request the **content time**\nfor a given **stream time** and the **stream time** for a given **content\ntime** . Using these conversion methods you can store the bookmarked\n**content time** and then seek to the corresponding **stream time** in\nthe new instance of the stream. Here's the approach, including a link\nto a sample app that shows a working bookmarking implementation.\n\nSaving bookmarks\n----------------\n\nSave a bookmark when the `Activity` is paused. \n\n private double bookmarkTime;\n @Override\n public void onPause() {\n super.onPause();\n double streamTime = videoPlayer.getCurrentPosition() / 1000.0; // ms to s.\n bookmarkTime = streamManager.getContentTimeForStreamTime(streamTime);\n }\n\nLoading bookmarks\n-----------------\n\nLoad the bookmark when re-requesting a stream. It's part of implementing\nthe `VideoStreamPlayer` interface. \n\n public void loadUrl(String url, List\u003cHashMap\u003cString, String\u003e\u003e subtitles) {\n // Set video player's stream URL and subtitles, and play the stream.\n ...\n\n // Bookmarking.\n if (bookmarkTime \u003e 0) {\n double streamTime =\n streamManager.getStreamTimeForContentTime(bookmarkTime);\n videoPlayer.seek((long) (streamTime * 1000.0)); // s to ms.\n }\n }\n\nSample app\n----------\n\n[Download the Sample app](//github.com/googleads/googleads-ima-android-dai)\nto see a bookmarking implementation."]]