सूची बनाना

खास जानकारी

वेब रिसीवर SDK टूल, QueueDataऔर QueueManager का इस्तेमाल करके, SDK टूल से मिली डिफ़ॉल्ट सूची की सूची बनाता है या अपडेट पाने के लिए, cast.framework.QueueBase लागू करता है और QueueManager का इस्तेमाल करता है.

सूची बनाने वाला एपीआई, नीचे दी गई सुविधाएं देकर ऐप्लिकेशन को कास्ट के साथ बेहतर तरीके से जोड़ने की अनुमति देता है:

  • Google और पार्टनर की क्लाउड सूची लागू करने की सुविधा, ताकि बाहरी तौर पर सेव की गई और बनाई गई सूची सीधे कास्ट डिवाइस पर लोड की जा सके.
  • मैकेनिज़्म की मदद से, पेजों को एक ही जगह पर क्रम में लगाने के बजाय, कॉन्टेंट को क्रम में लगाया जाता है.
  • नए मैसेज के लिए सहायता, जैसे कि अगले आइटम पर जाना, पिछले आइटम पर जाना, आइटम की विंडो लाना, साथ ही सूची आइटम के सेट से जुड़ी मीडिया की जानकारी पाना.
  • QueueManager सूची में शामिल आइटम को डालने, हटाने, और अपडेट करने की प्रोसेस को मैनेज करता है.

डिफ़ॉल्ट क्यू

वेब रिसीवर SDK टूल, डिफ़ॉल्ट सूची के रूप में बॉक्स से बाहर सीमित सूची सहायता देता है.

डिफ़ॉल्ट सूची का इस्तेमाल करने के लिए, queueData को भेजने वाले की ओर से मिलने वाले LoadRequestData के LoadRequestData में दें या PlayerManager#load का इस्तेमाल करके, स्थानीय लोड का अनुरोध भेजें. मीडिया लोड करना भी देखें.

रिसीवर की तरफ़ से, शुरुआती मीडिया लोड होने के बाद QueueManager का इस्तेमाल करके सूची में बदलाव किया जा सकता है.

कस्टम सूची

अगर डिफ़ॉल्ट सूची में आपके ऐप्लिकेशन के लिए ज़रूरी सूची बनाने की सुविधा उपलब्ध नहीं है, तो पसंद के मुताबिक सूची बनाने की सुविधा उपलब्ध है जिससे ऐप्लिकेशन को बेहतर तरीके से चलाने की सुविधा मिलती है.

ऐप्लिकेशन डेवलपर, cast.framework.QueueBase लागू करके वेब रिसीवर साइड सूची बना सकते हैं.

यहां एक सामान्य सूची का बुनियादी उदाहरण दिया गया है, जिसमें initialize कॉल को बदल दिया गया है. इसके बाद, सूची की जानकारी के साथ सूची में शामिल आइटम की सूची, कास्ट डिवाइस पर दी गई है.

मीडिया लोड करना भी देखें.

// Creates a simple queue with a combination of contents.
const DemoQueue = class extends cast.framework.QueueBase {
 constructor() {
   super();

   /**
    * List of media urls.
    * @private @const {!Array<string>}
    */
   this.myMediaUrls_ = [...];
 }
 /**
  * Provide a list of items.
  * @param {!cast.framework.messages.LoadRequestData} loadRequestData
  * @return {!cast.framework.messages.QueueData}
  */
 initialize(loadRequestData) {
   const items = [];
   for (const mediaUrl of this.myMediaUrls_) {
     const item = new cast.framework.messages.QueueItem();
     item.media = new cast.framework.messages.MediaInformation();
     item.media.contentId = mediaUrl;
     items.push(item);
   }
   let queueData = loadRequestData.queueData;
   // Create a new queue with media from the load request if one doesn't exist.
   if (!queueData) {
     queueData = new cast.framework.messages.QueueData();
     queueData.name = 'Your Queue Name';
     queueData.description = 'Your Queue Description';
     queueData.items = items;
     // Start with the first item in the playlist.
     queueData.startIndex = 0;
     // Start from 10 seconds into the first item.
     queueData.currentTime = 10;
   }
   return queueData;
 }
};

इस उदाहरण में, initialize कॉल में मौजूद आइटम की सूची, सेवा देने वाली कंपनी के QueueBase कंस्ट्रक्टर कॉल में दी गई है. हालांकि, क्लाउड सूची को लागू करने के लिए, कस्टम वेब रिसीवर लॉजिक, बाहर से आइटम को फ़ेच कर सकता है और फिर कॉल को शुरू करने के हिस्से के तौर पर उन्हें दे सकता है.

सूची बनाने वाले एपीआई को बेहतर तरीके से इस्तेमाल करने के लिए, यहां एक डेमो सूची दी गई है जिसमें, ज़्यादातर QueueBase क्लास को लागू किया गया है.

const DemoQueue = class extends cast.framework.QueueBase {
 constructor() {
   /** @private {} */
   super();
   YourServer.onSomeEvent = this.updateEntireQueue_;
 }

 /**
  * Initializes the queue.
  * @param {!cast.framework.messages.LoadRequestData} loadRequestData
  * @return {!cast.framework.messages.QueueData}
  */
 initialize(loadRequestData) {
   let queueData = loadRequestData.queueData;
   // Create a new queue with media from the load request if one doesn't exist.
   if (!queueData) {
     queueData = new cast.framework.messages.QueueData();
     queueData.name = 'Your Queue Name';
     queueData.description = 'Your Queue Description';
     // Put the first set of items into the queue
     const items = this.nextItems();
     queueData.items = items;
     // Start with the first item in the playlist.
     queueData.startIndex = 0;
     // Start from 10 seconds into the first item.
     queueData.currentTime = 10;
   }
   return queueData;
 }

 /**
  * Picks a set of items from remote server after the reference item id and
  * return as the next items to be inserted into the queue. When
  * referenceItemId is omitted, items are simply appended to the end of the
  * queue.
  * @param {number} referenceItemId
  * @return {!Array<cast.framework.QueueItem>}
  */
 nextItems(referenceItemId) {
   // Assume your media has a itemId and the media url
   return this.constructQueueList_(YourServer.getNextMedias(referenceItemId));
 }

 /**
  * Picks a set of items from remote server before the reference item id and
  * return as the items to be inserted into the queue. When
  * referenceItemId is omitted, items are simply appended to beginning of the
  * queue.
  * @param {number} referenceItemId
  * @return {!Array<cast.framework.QueueItem>}
  */
 prevItems(referenceItemId) {
   return this.constructQueueList_(YourServer.getPrevMedias(referenceItemId));
 }

 /**
  * Constructs a list of QueueItems based on the media information containing
  * the item id and the media url.
  * @param {number} referenceItemId
  * @return {!Array<cast.framework.QueueItem>}
  */
 constructQueueList_(medias) {
   const items = [];
   for (media of medias) {
     const item = new cast.framework.messages.QueueItem(media.itemId);
     item.media = new cast.framework.messages.MediaInformation();
     item.media.contentId = media.url;
     items.push(item);
   }
   return items;
 }

 /**
  * Logs the currently playing item.
  * @param {number} itemId The unique id for the item.
  * @export
  */
 onCurrentItemIdChanged(itemId) {
   console.log('We are now playing video ' + itemId);
   YourServer.trackUsage(itemId);
 }
};

ऊपर दिए गए उदाहरण में, YourServer आपका क्लाउड सूची सर्वर है और इसमें कुछ मीडिया आइटम फ़ेच करने का तरीका है.

लागू की गई सूची QueueBase का इस्तेमाल करने के लिए, CastReceiverContext में सूची बनाने के विकल्प को सेट करें:

const context = cast.framework.CastReceiverContext.getInstance();
context.start({queue: new DemoQueue()});

सूची को मैनेज करना

QueueManager डेवलपर को सूची में शामिल आइटम की सूची को ऐक्सेस करने के तरीके उपलब्ध कराता है. साथ ही, सूची में दिखाए गए मौजूदा आइटम को ऐक्सेस करने के तरीके उपलब्ध कराता है. इससे, सूची में शामिल करने, हटाने, और अपडेट करने जैसी कार्रवाइयां भी की जा सकती हैं. नीचे दिया गया स्निपेट, QueueManager के किसी इंस्टेंस को ऐक्सेस करने का तरीका बताता है:

const context = cast.framework.CastReceiverContext.getInstance();
const queueManager = context.getPlayerManager().getQueueManager();

डिफ़ॉल्ट सूची प्रबंधन

शुरुआती सूची लोड होने के बाद, QueueManager का इस्तेमाल मौजूदा आइटम को वापस पाने, सूची में मौजूद सभी आइटम वापस लाने, और insertItems, removeItems, और updateItems का इस्तेमाल करके सूची में आइटम अपडेट करने जैसी कार्रवाइयां करने के लिए किया जा सकता है.

कस्टम क्यू को मैनेज करना

यहां कस्टम सूची को लागू करने का एक उदाहरण दिया गया है. इसमें कुछ इवेंट के आधार पर, इंसर्शन और हटाने के तरीकों का इस्तेमाल किया गया है. इस उदाहरण में updateItems के इस्तेमाल के बारे में भी बताया गया है. इसमें डेवलपर, मौजूदा सूची की सूची में मौजूद आइटम में बदलाव कर सकते हैं, जैसे कि विज्ञापन के लिए ब्रेक हटाना.

const DemoQueue = class extends cast.framework.QueueBase {
  constructor() {
    super();

    /** @private @const {!cast.framework.QueueManager} */
    this.queueManager_ = context.getPlayerManager().getQueueManager();
  }

  /**
   * Provide a list of items.
   * @param {!cast.framework.messages.LoadRequestData} loadRequestData
   * @return {!cast.framework.messages.QueueData}
   */
  initialize(loadRequestData) {
    // Your normal initialization; see examples above.
    return queueData;
  }

  /** Inserts items to the queue. */
  onSomeEventTriggeringInsertionToQueue() {
    const twoMoreUrls = ['http://url1', 'http://url2'];
    const items = [];
    for (const mediaUrl of twoMoreUrls) {
      const item = new cast.framework.QueueItem();
      item.media = new cast.framework.messages.MediaInformation();
      item.media.contentId = mediaUrl;
      items.push(item);
    }
    // Insert two more items after the current playing item.
    const allItems = this.queueManager_.getItems();
    const currentItemIndex = this.queueManager_.getCurrentItemIndex();
    const nextItemIndex = currentItemIndex + 1;
    let insertBefore = undefined;
    if (currentItemIndex >= 0 &&
        currentItemIndex < allItems.length - 1) {
      insertBefore = allItems[nextItemIndex].itemId;
    }
    this.queueManager_.insertItems(items, insertBefore);
  }

  /** Removes a particular item from the queue. */
  onSomeEventTriggeringRemovalFromQueue() {
    this.queueManager_.removeItems([2]);
  }

  /** Removes all the ads from all the items across the entire queue. */
  onUserBoughtAdFreeVersion() {
    const items = this.queueManager_.getItems();
    this.queueManager_.updateItems(items.map(item => {
      item.media.breaks = undefined;
      return item;
    }));
  }
};

इनकमिंग और आउटगोइंग मैसेज

रिसीवर की ओर से फ़ेच की गई जानकारी को सच्चाई के स्रोत के तौर पर पूरी तरह से इस्तेमाल करने के लिए, CAF की ओर से अनुरोध करने वाले SDK टूल की मदद से, यहां दिए गए सूची में शामिल किए जाने वाले कुछ दूसरे मैसेज को पेश किया जाता है और मैनेज किया जाता है:

आने वाला मैसेज पैरामीटर आउटगोइंग जवाब मैसेज लौटें
आगे बढ़ें किसी पैरामीटर की ज़रूरत नहीं है. MEDIA_STATUS रिसीवर (ज़रूरी होने पर, NextItems() के ज़रिए फ़ेच करेगा) और अगला आइटम खेलना शुरू कर देगा.
पीछे जाएं किसी पैरामीटर की ज़रूरत नहीं है. MEDIA_STATUS वेब रिसीवर (ज़रूरी होने पर, prevItems() से फ़ेच करेगा) और पिछला आइटम चलाना शुरू करेगा.
FETCH_ITEMS FetchItemsRequestData QUEUE_CHANGE Cast.framework.messages.QueueChange. उदाहरण के तौर पर, 'शामिल करें' केस के लिए, JSON में आइटम फ़ील्ड में फ़ेच किए गए नए आइटम की सूची शामिल होगी.
GET_ITEMS_INFO GetItemInfoRequestData जिसमें itemIds शामिल है: श्रेणी<number> आइटम_जानकारी Cast.framework.messages.ItemsInfo, आइटम की सूची में शामिल है.
GET_QUEUE_IDS किसी पैरामीटर की ज़रूरत नहीं है. QUEUE_IDS Cast.framework.messages.QueueIds.

अगर NEXT/PREVIOUS के लिए, वेब पाने वाले पर पहले से मौजूद सूची में और आइटम नहीं हैं, तो ज़्यादा आइटम पाने के लिए, QueueBase.nextItems() या QueueBase.prevItems() को अपने-आप शुरू कर दिया जाता है.

FETCH_ITEM के लिए, QueueBase लागू करने के फ़ंक्शन में, fetchItems फ़ंक्शन को क्लाउड की सूचियों के लिए कॉल किया जाता है. इससे, 'वेब रिसीवर' को स्टोर करने के लिए, काम का डेटा वापस मिलता है.

जब भी और आइटम फ़ेच किए जाते हैं, तो एक नया मैसेज टाइप QUEUE_CHANGE ट्रिगर हो जाता है और भेजने वाले को वापस भेज दिया जाता है. अलग-अलग तरह के सूची में हुए बदलावों को देखें.

GET_ITEMS_INFO के लिए, QueueBase को लागू करने की प्रोसेस ट्रिगर नहीं की जाती है. साथ ही, वेब रिसीवर मीडिया की जानकारी दिखता है जो पहले से ही आईडी की सूची में होती है.

सूची को शफ़ल करना

सूची में मौजूद किसी आइटम को शफ़ल करने के लिए, QueueData के फ़्लैग को true पर सेट करें.

अगर आप QueueBase लागू करने का इस्तेमाल कर रहे हैं, तो आइटम की शफ़ल की गई सूची दिखाने के लिए, shuffle तरीके का इस्तेमाल करें.

किसी मौजूदा सूची को शफ़ल करने के लिए, QUEUE_SHUFFLE कमांड के बजाय QUEUE_UPDATEMessageType के shuffle फ़्लैग का इस्तेमाल करें. ज़्यादा जानकारी के लिए, QueueUpdateRequestData देखें.

दोहराने वाला मोड

अपनी सूची में मौजूद आइटम को दोहराए जाने के लिए, QueueData की प्रॉपर्टी QueueData को पसंद के मुताबिक RepeatMode पर सेट करें.

किसी मौजूदा सूची की RepeatMode बदलने के लिए, QueueUpdateRequestData की प्रॉपर्टी का इस्तेमाल करें, जो QUEUE_UPDATE MessageType का इस्तेमाल करती है.