يتيح ExoPlayer استخدام بروتوكول HLS مع تنسيقات حاوية متعددة. يجب أيضًا أن تكون تنسيقات نماذج الصوت و الفيديو المضمّنة متاحة (راجِع قسم تنسيقات النماذج لمزيد من التفاصيل). ننصح بشدة منتِجي محتوى HLS بإنشاء بثوث HLS عالية الجودة، كما هو موضّح في منشور المدوّنة هذا.
| الميزة | متاح | التعليقات |
|---|---|---|
| الحاويات | ||
| MPEG-TS | نعم | |
| FMP4/CMAF | نعم | |
| ADTS (AAC) | نعم | |
| MP3 | نعم | |
| الترجمة والشرح / الترجمة | ||
| CEA-608 | نعم | |
| CEA-708 | نعم | |
| WebVTT | نعم | |
| البيانات الوصفية | ||
| ID3 | نعم | |
| SCTE-35 | لا | |
| حماية المحتوى | ||
| AES-128 | نعم | |
| نموذج AES-128 | لا | |
| Widevine | نعم | واجهة برمجة التطبيقات 19 والإصدارات الأحدث (مخطط "cenc") و25 والإصدارات الأحدث (مخطط "cbcs") |
| PlayReady SL2000 | نعم | Android TV فقط |
| التحكّم في الخادم | ||
| تعديلات دلتا | نعم | |
| حظر إعادة تحميل قائمة التشغيل | نعم | |
| حظر تحميل تلميحات التحميل المسبق | نعم | باستثناء نطاقات البايت ذات الأطوال غير المحدّدة |
| إدراج الإعلانات | ||
| إدراج الإعلانات الموجَّه من الخادم (الإعلانات البينية) | جزئيًا | فيديوهات عند الطلب فقط مع X-ASSET-URI.
ستتم إضافة أحداث البث المباشر وX-ASSET-LIST لاحقًا. |
| إعلانات IMA من جهة الخادم ومن جهة العميل | نعم | دليل إدراج الإعلانات |
| تشغيل البث المباشر | ||
| تشغيل البث المباشر العادي | نعم | |
| بروتوكول HLS مع وقت استجابة سريع (Apple) | نعم | |
| بروتوكول HLS مع وقت استجابة سريع (المنتدى) | لا | |
| بيانات عميل الوسائط الشائعة CMCD | نعم | دليل دمج CMCD |
استخدام MediaItem
لتشغيل بث HLS، عليك الاعتماد على وحدة HLS.
Kotlin
implementation("androidx.media3:media3-exoplayer-hls:1.10.0")
أنيق
implementation "androidx.media3:media3-exoplayer-hls:1.10.0"
يمكنك بعد ذلك إنشاء MediaItem لمعرّف URI لقائمة تشغيل HLS وتمريره إلى المشغّل.
Kotlin
// Create a player instance. val player = ExoPlayer.Builder(context).build() // Set the media item to be played. player.setMediaItem(MediaItem.fromUri(hlsUri)) // Prepare the player. player.prepare()
Java
// Create a player instance. ExoPlayer player = new ExoPlayer.Builder(context).build(); // Set the media item to be played. player.setMediaItem(MediaItem.fromUri(hlsUri)); // Prepare the player. player.prepare();
إذا لم ينتهِ معرّف URI بـ .m3u8، يمكنك تمرير MimeTypes.APPLICATION_M3U8 إلى setMimeType في MediaItem.Builder للإشارة بوضوح إلى نوع المحتوى.
قد يشير معرّف URI لعنصر الوسائط إلى قائمة تشغيل وسائط أو قائمة تشغيل متعددة الخيارات. إذا كان معرّف URI يشير إلى قائمة تشغيل متعددة الخيارات تتضمّن علامات #EXT-X-STREAM-INF متعددة، سيتم تلقائيًا تكييف ExoPlayer بين الخيارات، مع أخذ كلّ من النطاق الترددي المتاح وإمكانات الجهاز في الاعتبار.
استخدام HlsMediaSource
لمزيد من خيارات التخصيص، يمكنك إنشاء HlsMediaSource وتمريره مباشرةً إلى المشغّل بدلاً من MediaItem.
Kotlin
// Create a data source factory. val dataSourceFactory: DataSource.Factory = DefaultHttpDataSource.Factory() // Create a HLS media source pointing to a playlist uri. val hlsMediaSource = HlsMediaSource.Factory(dataSourceFactory).createMediaSource(MediaItem.fromUri(hlsUri)) // Create a player instance. val player = ExoPlayer.Builder(context).build() // Set the HLS media source as the playlist with a single media item. player.setMediaSource(hlsMediaSource) // Prepare the player. player.prepare()
Java
// Create a data source factory. DataSource.Factory dataSourceFactory = new DefaultHttpDataSource.Factory(); // Create a HLS media source pointing to a playlist uri. HlsMediaSource hlsMediaSource = new HlsMediaSource.Factory(dataSourceFactory).createMediaSource(MediaItem.fromUri(hlsUri)); // Create a player instance. ExoPlayer player = new ExoPlayer.Builder(context).build(); // Set the HLS media source as the playlist with a single media item. player.setMediaSource(hlsMediaSource); // Prepare the player. player.prepare();
الوصول إلى ملف البيان
يمكنك استرداد ملف البيان الحالي من خلال طلب Player.getCurrentManifest.
بالنسبة إلى HLS، عليك تحويل الكائن الذي تم عرضه إلى HlsManifest. يتم أيضًا استدعاء معاودة الاتصال onTimelineChanged في Player.Listener كلما تم تحميل ملف البيان. سيحدث ذلك مرة واحدة للمحتوى عند الطلب، وقد يحدث عدة مرات للمحتوى المباشر. يوضّح مقتطف الرمز البرمجي التالي كيف يمكن لتطبيق تنفيذ إجراء ما كلما تم تحميل ملف البيان.
Kotlin
player.addListener( object : Player.Listener { override fun onTimelineChanged( timeline: Timeline, @Player.TimelineChangeReason reason: Int, ) { val manifest = player.currentManifest if (manifest is HlsManifest) { // Do something with the manifest. } } } )
Java
player.addListener( new Player.Listener() { @Override public void onTimelineChanged( Timeline timeline, @Player.TimelineChangeReason int reason) { Object manifest = player.getCurrentManifest(); if (manifest != null) { HlsManifest hlsManifest = (HlsManifest) manifest; // Do something with the manifest. } } });
تشغيل بثوث HLS مع إعلانات بينية
تحدّد مواصفات HLS الإعلانات البينية لبروتوكول HLS التي يمكن استخدامها لتضمين معلومات الإعلانات البينية في قائمة تشغيل الوسائط. يتجاهل ExoPlayer هذه الإعلانات البينية تلقائيًا. يمكن إضافة الدعم باستخدام HlsInterstitialsAdsLoader. لا نتيح جميع ميزات المواصفات منذ البداية. إذا لم يكن البث متاحًا، يُرجى إعلامنا من خلال الإبلاغ عن مشكلة على GitHub وإرسال معرّف URI للبث إلينا، حتى نتمكّن من إضافة الدعم له.
استخدام MediaItem مع واجهة برمجة تطبيقات قائمة التشغيل
إنّ الطريقة الأكثر ملاءمة لتشغيل بثوث HLS مع إعلانات بينية هي إنشاء مثيل ExoPlayer باستخدام HlsInterstitialsAdsLoader.AdsMediaSourceFactory.
يتيح ذلك استخدام واجهة برمجة تطبيقات قائمة التشغيل المستندة إلى MediaItem في واجهة Player
لتشغيل الإعلانات البينية لبروتوكول HLS.
يمكن إدخال MediaSource.Factory في ExoPlayer في أداة الإنشاء عند إنشاء مثيل المشغّل:
Kotlin
val hlsInterstitialsAdsLoader = HlsInterstitialsAdsLoader(context) // Create a MediaSource.Factory for HLS streams with interstitials. val hlsMediaSourceFactory = HlsInterstitialsAdsLoader.AdsMediaSourceFactory( hlsInterstitialsAdsLoader, playerView, DefaultMediaSourceFactory(context), ) // Build player with interstitials media source factory val player = ExoPlayer.Builder(context).setMediaSourceFactory(hlsMediaSourceFactory).build() // Set the player on the ads loader. hlsInterstitialsAdsLoader.setPlayer(player) playerView.setPlayer(player)
Java
HlsInterstitialsAdsLoader hlsInterstitialsAdsLoader = new HlsInterstitialsAdsLoader(context); // Create a MediaSource.Factory for HLS streams with interstitials. MediaSource.Factory hlsMediaSourceFactory = new HlsInterstitialsAdsLoader.AdsMediaSourceFactory( hlsInterstitialsAdsLoader, playerView, new DefaultMediaSourceFactory(context)); // Build player with interstitials media source factory ExoPlayer player = new ExoPlayer.Builder(context).setMediaSourceFactory(hlsMediaSourceFactory).build(); // Set the player on the ads loader. hlsInterstitialsAdsLoader.setPlayer(player); playerView.setPlayer(player);
باستخدام إعداد المشغّل هذا، لا يتطلّب تشغيل الإعلانات البينية لبروتوكول HLS سوى ضبط عنصر وسائط باستخدام AdsConfiguration على المشغّل:
Kotlin
// Build an HLS media item with ads configuration to be played. player.setMediaItem( MediaItem.Builder() .setUri("https://www.example.com/media.m3u8") .setAdsConfiguration( MediaItem.AdsConfiguration.Builder("hls://interstitials".toUri()) .setAdsId("ad-tag-0") // must be unique within playlist .build() ) .build() ) player.prepare() player.play()
Java
// Build an HLS media item with ads configuration to be played. player.setMediaItem( new MediaItem.Builder() .setUri("https://www.example.com/media.m3u8") .setAdsConfiguration( new AdsConfiguration.Builder(Uri.parse("hls://interstitials")) .setAdsId("ad-tag-0") // must be unique within playlist .build()) .build()); player.prepare(); player.play();
استخدام واجهة برمجة التطبيقات المستندة إلى مصدر الوسائط
بدلاً من ذلك، يمكن إنشاء مثيل ExoPlayer بدون إلغاء الإعدادات التلقائية لمصنع مصدر الوسائط. لدعم الإعلانات البينية، يمكن لتطبيق استخدام HlsInterstitialsAdsLoader.AdsMediaSourceFactory مباشرةً لإنشاء MediaSource وتقديمه إلى ExoPlayer باستخدام واجهة برمجة تطبيقات قائمة التشغيل المستندة إلى مصدر الوسائط:
Kotlin
val hlsInterstitialsAdsLoader = HlsInterstitialsAdsLoader(context) // Create a MediaSource.Factory for HLS streams with interstitials. val hlsMediaSourceFactory = HlsInterstitialsAdsLoader.AdsMediaSourceFactory( hlsInterstitialsAdsLoader, playerView, context, ) // Build player with default media source factory. val player = ExoPlayer.Builder(context).build() // Create an media source from an HLS media item with ads configuration. val mediaSource = hlsMediaSourceFactory.createMediaSource( MediaItem.Builder() .setUri("https://www.example.com/media.m3u8") .setAdsConfiguration( MediaItem.AdsConfiguration.Builder("hls://interstitials".toUri()) .setAdsId("ad-tag-0") .build() ) .build() ) // Set the media source on the player. player.setMediaSource(mediaSource) player.prepare() player.play()
Java
HlsInterstitialsAdsLoader hlsInterstitialsAdsLoader = new HlsInterstitialsAdsLoader(context); // Create a MediaSource.Factory for HLS streams with interstitials. MediaSource.Factory hlsMediaSourceFactory = new HlsInterstitialsAdsLoader.AdsMediaSourceFactory( hlsInterstitialsAdsLoader, playerView, context); // Build player with default media source factory. ExoPlayer player = new ExoPlayer.Builder(context).build(); // Create a media source from an HLS media item with ads configuration. MediaSource mediaSource = hlsMediaSourceFactory.createMediaSource( new MediaItem.Builder() .setUri("https://www.example.com/media.m3u8") .setAdsConfiguration( new MediaItem.AdsConfiguration.Builder(Uri.parse("hls://interstitials")) .setAdsId("ad-tag-0") .build()) .build()); // Set the media source on the player. player.setMediaSource(mediaSource); player.prepare(); player.play();
الاستماع إلى أحداث الإعلانات
يمكن إضافة Listener إلى HlsInterstitialsAdsLoader لتتبُّع الأحداث المتعلقة بتغييرات الحالة بشأن تشغيل الإعلانات البينية لبروتوكول HLS. يتيح ذلك لتطبيق أو حزمة تطوير برامج (SDK) تتبُّع الإعلانات التي يتم تشغيلها، وقوائم مواد العرض التي يتم تحميلها، ومصادر وسائط الإعلانات التي يتم إعدادها، أو رصد أخطاء تحميل قائمة مواد العرض وإعداد الإعلانات. علاوةً على ذلك، يمكن تلقّي البيانات الوصفية التي تنبعث من مصادر وسائط الإعلانات للتحقّق من تشغيل الإعلانات بدقة أو لتتبُّع تقدّم تشغيل الإعلانات.
Kotlin
class AdsLoaderListener : HlsInterstitialsAdsLoader.Listener { override fun onStart(mediaItem: MediaItem, adsId: Any, adViewProvider: AdViewProvider) { // Do something when HLS media item with interstitials is started. } override fun onMetadata( mediaItem: MediaItem, adsId: Any, adGroupIndex: Int, adIndexInAdGroup: Int, metadata: Metadata, ) { // Do something with metadata that is emitted by the ad media source of the given ad. } override fun onAdCompleted( mediaItem: MediaItem, adsId: Any, adGroupIndex: Int, adIndexInAdGroup: Int, ) { // Do something when ad completed playback. } // ... See JavaDoc for further callbacks of HlsInterstitialsAdsLoader.Listener. override fun onStop(mediaItem: MediaItem, adsId: Any, adPlaybackState: AdPlaybackState) { // Do something with the resulting ad playback state when stopped. } }
Java
@OptIn(markerClass = UnstableApi.class) private static class AdsLoaderListener implements HlsInterstitialsAdsLoader.Listener { // implement HlsInterstitialsAdsLoader.Listener @Override public void onStart(MediaItem mediaItem, Object adsId, AdViewProvider adViewProvider) { // Do something when HLS media item with interstitials is started. } @Override public void onMetadata( MediaItem mediaItem, Object adsId, int adGroupIndex, int adIndexInAdGroup, Metadata metadata) { // Do something with metadata that is emitted by the ad media source of the given ad. } @Override public void onAdCompleted( MediaItem mediaItem, Object adsId, int adGroupIndex, int adIndexInAdGroup) { // Do something when ad completed playback. } // ... See JavaDoc for further callbacks @Override public void onStop(MediaItem mediaItem, Object adsId, AdPlaybackState adPlaybackState) { // Do something with the resulting ad playback state when stopped. } }
راجِع JavaDoc في HlsInterstitialsAdsLoader.Listener للحصول على الوثائق التفصيلية
لجميع معاودات الاتصال المتاحة.
يمكن بعد ذلك إضافة المستمع إلى أداة تحميل الإعلانات:
Kotlin
val listener = AdsLoaderListener() // Add the listener to the ads loader to receive ad loader events. hlsInterstitialsAdsLoader.addListener(listener)
Java
AdsLoaderListener listener = new AdsLoaderListener(); // Add the listener to the ads loader to receive ad loader events. hlsInterstitialsAdsLoader.addListener(listener);
دورة حياة HlsInterstitialsAdsLoader
يمكن إعادة استخدام مثيل HlsInterstitialsAdsLoader أو
HlsInterstitialsAdsLoader.AdsMediaSourceFactory لمثيلات مشغّل متعددة تنشئ مصادر وسائط متعددة يجب تحميل الإعلانات لها.
يمكن إنشاء مثيل مثلاً في طريقة onCreate في Activity ثم إعادة استخدامه لمثيلات مشغّل متعددة. يعمل ذلك طالما أنّه قيد الاستخدام من قِبل مثيل مشغّل واحد في الوقت نفسه. ويُفيد ذلك في حالة الاستخدام الشائعة عندما يتم نقل التطبيق إلى الخلفية، ويتم إتلاف مثيل المشغّل، ثم يتم إنشاء مثيل جديد عند إعادة عرض التطبيق في المقدّمة.
استئناف التشغيل باستخدام حالة تشغيل إعلان
لتجنُّب اضطرار المستخدمين إلى إعادة مشاهدة الإعلانات، يمكن حفظ حالة تشغيل الإعلان واستعادتها عند إعادة إنشاء المشغّل. يتم ذلك من خلال طلب
getAdsResumptionStates() عندما يكون المشغّل على وشك إيقافه وتخزين
الكائنات AdsResumptionState التي تم عرضها. عند إعادة إنشاء المشغّل، يمكن استعادة الحالة من خلال طلب addAdResumptionState() في مثيل أداة تحميل الإعلانات. AdsResumptionState قابلة للتجميع، لذا يمكن تخزينها في حزمة onSaveInstanceState في Activity. يُرجى العِلم أنّ استئناف الإعلانات لا يكون متاحًا إلا لبثوث الفيديو عند الطلب.
Kotlin
class HlsInterstitialsActivity : Activity() { companion object { const val ADS_RESUMPTION_STATE_KEY = "ads_resumption_state" } private var hlsInterstitialsAdsLoader: HlsInterstitialsAdsLoader? = null private var playerView: PlayerView? = null private var player: ExoPlayer? = null private var adsResumptionStates: List<HlsInterstitialsAdsLoader.AdsResumptionState>? = null @Suppress("DEPRECATION") // getParcelableArrayList without class type is deprecated in API 33+ override fun onCreate(savedInstanceState: Bundle?) { super.onCreate(savedInstanceState) // Create the ads loader instance. hlsInterstitialsAdsLoader = HlsInterstitialsAdsLoader(this) // Restore ad resumption states. val bundles = if (Build.VERSION.SDK_INT >= 33) { savedInstanceState?.getParcelableArrayList(ADS_RESUMPTION_STATE_KEY, Bundle::class.java) } else { savedInstanceState?.getParcelableArrayList(ADS_RESUMPTION_STATE_KEY) } adsResumptionStates = bundles?.map(HlsInterstitialsAdsLoader.AdsResumptionState::fromBundle) } override fun onStart() { super.onStart() // Build a player and set it on the ads loader. initializePlayer() hlsInterstitialsAdsLoader?.setPlayer(player) // Add any stored ad resumption states to the ads loader. adsResumptionStates?.forEach { hlsInterstitialsAdsLoader?.addAdResumptionState(it) } adsResumptionStates = null // Consume the states } override fun onStop() { super.onStop() // Get ad resumption states. adsResumptionStates = hlsInterstitialsAdsLoader?.adsResumptionStates releasePlayer() } override fun onDestroy() { // Release the ads loader when not used anymore. hlsInterstitialsAdsLoader?.release() hlsInterstitialsAdsLoader = null super.onDestroy() } override fun onSaveInstanceState(outState: Bundle) { super.onSaveInstanceState(outState) // Store the ad resumption states. adsResumptionStates?.let { outState.putParcelableArrayList( ADS_RESUMPTION_STATE_KEY, ArrayList(it.map(HlsInterstitialsAdsLoader.AdsResumptionState::toBundle)), ) } } fun initializePlayer() { if (player == null) { // Create a media source factory for HLS streams. val hlsMediaSourceFactory = HlsInterstitialsAdsLoader.AdsMediaSourceFactory( checkNotNull(hlsInterstitialsAdsLoader), playerView!!, /* context= */ this, ) // Build player with interstitials media source player = ExoPlayer.Builder(/* context= */ this) .setMediaSourceFactory(hlsMediaSourceFactory) .build() // Set the player on the ads loader. hlsInterstitialsAdsLoader?.setPlayer(player) playerView?.player = player } // Use a media item with an HLS stream URI, an ad tag URI and ads ID. player?.setMediaItem( MediaItem.Builder() .setUri("https://www.example.com/media.m3u8") .setMimeType(MimeTypes.APPLICATION_M3U8) .setAdsConfiguration( MediaItem.AdsConfiguration.Builder("hls://interstitials".toUri()) .setAdsId("ad-tag-0") // must be unique within ExoPlayer playlist .build() ) .build() ) player?.prepare() player?.play() } fun releasePlayer() { player?.release() player = null hlsInterstitialsAdsLoader?.setPlayer(null) playerView?.player = null } }
Java
@OptIn(markerClass = UnstableApi.class) public static class HlsInterstitialsActivity extends Activity { public static final String ADS_RESUMPTION_STATE_KEY = "ads_resumption_state"; @Nullable private HlsInterstitialsAdsLoader hlsInterstitialsAdsLoader; @Nullable private PlayerView playerView; @Nullable private ExoPlayer player; private List<HlsInterstitialsAdsLoader.AdsResumptionState> adsResumptionStates; @SuppressWarnings( "deprecation") // getParcelableArrayList without class type is deprecated in API 33+ @Override protected void onCreate(@Nullable Bundle savedInstanceState) { super.onCreate(savedInstanceState); // Create the ads loader instance. hlsInterstitialsAdsLoader = new HlsInterstitialsAdsLoader(this); // Restore ad resumption states. if (savedInstanceState != null) { ArrayList<Bundle> bundles; if (Build.VERSION.SDK_INT >= 33) { bundles = savedInstanceState.getParcelableArrayList(ADS_RESUMPTION_STATE_KEY, Bundle.class); } else { bundles = savedInstanceState.getParcelableArrayList(ADS_RESUMPTION_STATE_KEY); } if (bundles != null) { adsResumptionStates = new ArrayList<>(); for (Bundle bundle : bundles) { adsResumptionStates.add( HlsInterstitialsAdsLoader.AdsResumptionState.fromBundle(bundle)); } } } } @Override protected void onStart() { super.onStart(); // Build a player and set it on the ads loader. initializePlayer(); // Add any stored ad resumption states to the ads loader. if (adsResumptionStates != null) { for (HlsInterstitialsAdsLoader.AdsResumptionState state : adsResumptionStates) { hlsInterstitialsAdsLoader.addAdResumptionState(state); } adsResumptionStates = null; // Consume the states } } @Override protected void onStop() { super.onStop(); // Get ad resumption states before releasing the player. if (hlsInterstitialsAdsLoader != null) { adsResumptionStates = hlsInterstitialsAdsLoader.getAdsResumptionStates(); } releasePlayer(); } @Override protected void onDestroy() { // Release the ads loader when not used anymore. if (hlsInterstitialsAdsLoader != null) { hlsInterstitialsAdsLoader.release(); hlsInterstitialsAdsLoader = null; } super.onDestroy(); } @Override protected void onSaveInstanceState(Bundle outState) { super.onSaveInstanceState(outState); // Store the ad resumption states. if (adsResumptionStates != null) { ArrayList<Bundle> bundles = new ArrayList<>(); for (HlsInterstitialsAdsLoader.AdsResumptionState state : adsResumptionStates) { bundles.add(state.toBundle()); } outState.putParcelableArrayList(ADS_RESUMPTION_STATE_KEY, bundles); } } private void initializePlayer() { if (player == null) { // Create a media source factory for HLS streams. MediaSource.Factory hlsMediaSourceFactory = new HlsInterstitialsAdsLoader.AdsMediaSourceFactory( checkNotNull(hlsInterstitialsAdsLoader), playerView, /* context= */ this); // Build player with interstitials media source player = new ExoPlayer.Builder(/* context= */ this) .setMediaSourceFactory(hlsMediaSourceFactory) .build(); // Set the player on the ads loader. hlsInterstitialsAdsLoader.setPlayer(player); playerView.setPlayer(player); } // Use a media item with an HLS stream URI, an ad tag URI and ads ID. player.setMediaItem( new MediaItem.Builder() .setUri("https://www.example.com/media.m3u8") .setMimeType(MimeTypes.APPLICATION_M3U8) .setAdsConfiguration( new MediaItem.AdsConfiguration.Builder(Uri.parse("hls://interstitials")) .setAdsId("ad-tag-0") // must be unique within ExoPlayer playlist .build()) .build()); player.prepare(); player.play(); } private void releasePlayer() { if (player != null) { player.release(); player = null; } if (hlsInterstitialsAdsLoader != null) { hlsInterstitialsAdsLoader.setPlayer(null); } if (playerView != null) { playerView.setPlayer(null); } } }
تخصيص التشغيل
يوفّر ExoPlayer طرقًا متعددة لتخصيص تجربة التشغيل بما يتناسب مع احتياجات تطبيقك. راجِع صفحة التخصيص للاطّلاع على أمثلة.
إيقاف الإعداد بدون أجزاء
سيستخدم ExoPlayer تلقائيًا الإعداد بدون أجزاء. يعني ذلك أنّ ExoPlayer سيستخدم فقط المعلومات الواردة في قائمة التشغيل متعددة الخيارات لإعداد البث، وهو ما ينجح إذا كانت علامات #EXT-X-STREAM-INF تحتوي على السمة CODECS.
قد تحتاج إلى إيقاف هذه الميزة إذا كانت أجزاء الوسائط تحتوي على مسارات ترجمة وشرح مدمجة غير معلَنة في قائمة التشغيل متعددة الخيارات باستخدام علامة #EXT-X-MEDIA:TYPE=CLOSED-CAPTIONS. وإلا، لن يتم رصد مسارات الترجمة والشرح هذه وتشغيلها. يمكنك إيقاف الإعداد بدون أجزاء في HlsMediaSource.Factory كما هو موضّح في المقتطف التالي. يُرجى العِلم أنّ ذلك سيؤدي إلى زيادة وقت بدء التشغيل لأنّ ExoPlayer يحتاج إلى تنزيل جزء وسائط لاكتشاف هذه المسارات الإضافية، ومن الأفضل الإعلان عن مسارات الترجمة والشرح في قائمة التشغيل متعددة الخيارات بدلاً من ذلك.
Kotlin
val hlsMediaSource = HlsMediaSource.Factory(dataSourceFactory) .setAllowChunklessPreparation(false) .createMediaSource(MediaItem.fromUri(hlsUri))
Java
HlsMediaSource hlsMediaSource = new HlsMediaSource.Factory(dataSourceFactory) .setAllowChunklessPreparation(false) .createMediaSource(MediaItem.fromUri(hlsUri));
إنشاء محتوى HLS عالي الجودة
للاستفادة إلى أقصى حدّ من ExoPlayer، يمكنك اتّباع إرشادات معيّنة لتحسين محتوى HLS. راجِع منشورنا على Medium حول تشغيل HLS في ExoPlayer للحصول على شرح كامل. في ما يلي النقاط الرئيسية:
- استخدِم مدة دقيقة للأجزاء.
- استخدِم بث وسائط مستمرًا، وتجنَّب إجراء تغييرات في بنية الوسائط بين الأجزاء.
- استخدِم العلامة
#EXT-X-INDEPENDENT-SEGMENTS. - فضِّل البثوث غير المدمجة، بدلاً من الملفات التي تتضمّن كلاً من الفيديو والصوت.
- أدرِج كل المعلومات التي يمكنك تضمينها في قائمة التشغيل متعددة الخيارات.
تنطبق الإرشادات التالية تحديدًا على أحداث البث المباشر:
- استخدِم العلامة
#EXT-X-PROGRAM-DATE-TIME. - استخدِم العلامة
#EXT-X-DISCONTINUITY-SEQUENCE. - وفِّر نافذة بث مباشر طويلة. دقيقة واحدة أو أكثر هي مدة رائعة.