स्मूदस्ट्रीमिंग

ExoPlayer, FMP4 कंटेनर फ़ॉर्मैट के साथ SmoothStreaming का इस्तेमाल करने की सुविधा देता है. मीडिया स्ट्रीम को डीमक्स किया जाना चाहिए. इसका मतलब है कि वीडियो, ऑडियो, और टेक्स्ट को SmoothStreaming मेनिफ़ेस्ट में अलग-अलग StreamIndex एलिमेंट में तय किया जाना चाहिए. इसमें शामिल ऑडियो और वीडियो सैंपल के फ़ॉर्मैट भी काम करने चाहिए. ज़्यादा जानकारी के लिए, सैंपल के फ़ॉर्मैट सेक्शन देखें.

सुविधा इनकी अनुमति है टिप्पणियां
कंटेनर
FMP4 हां सिर्फ़ डीमक्स की गई स्ट्रीम
सबटाइटल
TTML हां FMP4 में एम्बेड किया गया
कॉन्टेंट की सुरक्षा
PlayReady SL2000 हां सिर्फ़ Android TV के लिए
लाइव स्ट्रीम को फिर से चलाना
लाइव स्ट्रीम को सामान्य तरीके से चलाना हां
कॉमन मीडिया क्लाइंट डेटा (सीएमसीडी) हां इंटिग्रेशन गाइड

MediaItem का इस्तेमाल करना

SmoothStreaming स्ट्रीम चलाने के लिए, आपको SmoothStreaming मॉड्यूल पर निर्भर रहना होगा.

Kotlin

implementation("androidx.media3:media3-exoplayer-smoothstreaming:1.8.0")

Groovy

implementation "androidx.media3:media3-exoplayer-smoothstreaming:1.8.0"

इसके बाद, SmoothStreaming मेनिफ़ेस्ट यूआरआई के लिए MediaItem बनाया जा सकता है और इसे प्लेयर को पास किया जा सकता है.

Kotlin

// Create a player instance.
val player = ExoPlayer.Builder(context).build()
// Set the media item to be played.
player.setMediaItem(MediaItem.fromUri(ssUri))
// 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(ssUri));
// Prepare the player.
player.prepare();

अगर आपका यूआरआई .ism/Manifest पर खत्म नहीं होता है, तो कॉन्टेंट के टाइप के बारे में साफ़ तौर पर बताने के लिए, MediaItem.Builder के setMimeType को MimeTypes.APPLICATION_SS पास किया जा सकता है.

ExoPlayer, मेनिफ़ेस्ट में तय किए गए अलग-अलग वर्शन के बीच अपने-आप अडजस्ट हो जाएगा. इसके लिए, वह उपलब्ध बैंडविड्थ और डिवाइस की क्षमताओं को ध्यान में रखेगा.

SsMediaSource का इस्तेमाल करना

अपनी पसंद के मुताबिक बनाने के ज़्यादा विकल्पों के लिए, SsMediaSource बनाया जा सकता है. इसके बाद, इसे MediaItem के बजाय सीधे प्लेयर को पास किया जा सकता है.

Kotlin

// Create a data source factory.
val dataSourceFactory: DataSource.Factory = DefaultHttpDataSource.Factory()
// Create a SmoothStreaming media source pointing to a manifest uri.
val mediaSource: MediaSource =
  SsMediaSource.Factory(dataSourceFactory).createMediaSource(MediaItem.fromUri(ssUri))
// Create a player instance.
val player = ExoPlayer.Builder(context).build()
// Set the media source to be played.
player.setMediaSource(mediaSource)
// Prepare the player.
player.prepare()

Java

// Create a data source factory.
DataSource.Factory dataSourceFactory = new DefaultHttpDataSource.Factory();
// Create a SmoothStreaming media source pointing to a manifest uri.
MediaSource mediaSource =
    new SsMediaSource.Factory(dataSourceFactory).createMediaSource(MediaItem.fromUri(ssUri));
// Create a player instance.
ExoPlayer player = new ExoPlayer.Builder(context).build();
// Set the media source to be played.
player.setMediaSource(mediaSource);
// Prepare the player.
player.prepare();

मेनिफ़ेस्ट ऐक्सेस करना

Player.getCurrentManifest को कॉल करके, मौजूदा मेनिफ़ेस्ट को वापस पाया जा सकता है. SmoothStreaming के लिए, आपको लौटाए गए ऑब्जेक्ट को SsManifest में काफ़ी करना चाहिए. मेनिफ़ेस्ट लोड होने पर, Player.Listener का onTimelineChanged कॉलबैक भी कॉल किया जाता है. मांग पर उपलब्ध कॉन्टेंट के लिए ऐसा एक बार होगा. वहीं, लाइव कॉन्टेंट के लिए ऐसा कई बार हो सकता है. नीचे दिए गए कोड स्निपेट में दिखाया गया है कि मेनिफ़ेस्ट लोड होने पर, कोई ऐप्लिकेशन क्या कर सकता है.

Kotlin

player.addListener(
  object : Player.Listener {
    override fun onTimelineChanged(timeline: Timeline, @TimelineChangeReason reason: Int) {
      val manifest = player.currentManifest
      if (manifest is SsManifest) {
        // 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) {
          SsManifest ssManifest = (SsManifest) manifest;
          // Do something with the manifest.
        }
      }
    });

वीडियो चलाने की सुविधा को पसंद के मुताबिक बनाना

ExoPlayer, आपके ऐप्लिकेशन की ज़रूरतों के हिसाब से वीडियो चलाने की सुविधा को बेहतर बनाने के कई तरीके उपलब्ध कराता है. उदाहरणों के लिए, कस्टमाइज़ेशन पेज देखें.