概览
任意长度的媒体队列的数据模型表示法。
此类可用作实现 UITableViewDataSource 以驱动媒体队列界面的基础。
GCKMediaQueue 会监听 GCKSessionManager 事件,并在 Cast 会话启动时自动将其附加到 GCKRemoteMediaClient。它会监听来自 GCKRemoteMediaClient 的队列更改通知,并相应地更新其内部数据模型。同样,它会使用 GCKRemoteMediaClient 按需提取队列信息。
模型会维护整个队列的队列项 ID 列表;每当它连接到 Cast 会话时,它都会自动提取此列表。它还保留 GCKMediaQueueItems 的 LRU 缓存(大小可配置),由队列项 ID 进行键控。
itemAtIndex: (GCKMediaQueue) 方法用于提取位于指定索引处的队列项。如果 GCKMediaQueueItem 当前不在缓存中,系统会发出异步请求以从接收器提取该项,并且代理最终会在收到请求的项时收到通知。
如果在极短的时间内多次调用该方法,系统会在内部批量处理请求的商品 ID,以减少网络请求的数量。由于每次可以从接收器提取的队列项数量存在上限,因此 GCKMediaQueue 会保留要提取的最后 N 个项 ID 的滚动窗口。因此,如果在短时间内请求大量的项,则实际只会获取最后 N 个项。此行为有助于高效管理应用界面中可以快速和/或频繁滚动浏览的非常长的队列。
GCKMediaQueue 没有提供任何用于直接修改队列的方法,因为任何此类更改都涉及向接收器发出异步网络请求(通过 GCKRemoteMediaClient 上的方法),这可能会失败并报错。GCKMediaQueue 必须确保队列在接收器上存在的一致表示法,因此对接收器上尚未提交的数据模型进行本地更改可能会导致界面行为不正确。
如需了解委托协议,请参阅 GCKMediaQueueDelegate。
- 开始时间
- 4.3.4
此类继承 NSObject。
| 实例方法摘要 | |
| (instancetype) | - init | 
| (instancetype) | - initWithRemoteMediaClient: | 
| 初始化使用默认缓存大小和默认最大提取计数的新 GCKMediaQueue。更多... | |
| (instancetype) | - initWithRemoteMediaClient:cacheSize: | 
| 初始化具有指定缓存大小和默认最大提取计数的新 GCKMediaQueue。更多... | |
| (instancetype) | - initWithRemoteMediaClient:cacheSize:maxFetchCount: | 
| 初始化具有指定缓存大小和指定最大提取计数的新 GCKMediaQueue。更多... | |
| (void) | - addDelegate: | 
| 向此对象的委托列表添加委托。更多... | |
| (void) | - removeDelegate: | 
| 从此对象的委托列表中移除委托。更多... | |
| (nullable GCKMediaQueueItem *) | - itemAtIndex: | 
| 返回队列中给定索引处的媒体队列项,或者安排从接收器提取该媒体队列项(如果该项当前不在缓存中)。更多... | |
| (nullable GCKMediaQueueItem *) | - itemAtIndex:fetchIfNeeded: | 
| 返回队列中给定索引处的媒体队列项,或者视需要安排从接收器提取媒体项(如果媒体项当前不在缓存中)。更多... | |
| (GCKMediaQueueItemID) | - itemIDAtIndex: | 
| 返回队列中指定索引处的项 ID。更多... | |
| (NSInteger) | - indexOfItemWithID: | 
| 在队列中查找队列项的索引。更多... | |
| (void) | - reload | 
| 重新加载队列。更多... | |
| (void) | - clear | 
| 清空队列,移除所有元素并清除缓存。更多... | |
| 属性摘要 | |
| NSUInteger | itemCount | 
| 当前在队列中的项数。更多... | |
| NSUInteger | cacheSize | 
| 缓存大小。更多... | |
| NSUInteger | cachedItemCount | 
| 当前位于缓存中的队列项数量。更多... | |
方法详细信息
| - (instancetype) initWithRemoteMediaClient: | (GCKRemoteMediaClient *) | remoteMediaClient | 
初始化使用默认缓存大小和默认最大提取计数的新 GCKMediaQueue。
| - (instancetype) initWithRemoteMediaClient: | (GCKRemoteMediaClient *) | remoteMediaClient | |
| cacheSize: | (NSUInteger) | cacheSize | |
初始化具有指定缓存大小和默认最大提取计数的新 GCKMediaQueue。
- Parameters
- 
  cacheSize The cache size. Must be nonzero. 
| - (instancetype) initWithRemoteMediaClient: | (GCKRemoteMediaClient *) | remoteMediaClient | |
| cacheSize: | (NSUInteger) | cacheSize | |
| maxFetchCount: | (NSUInteger) | maxFetchCount | |
初始化具有指定缓存大小和指定最大提取计数的新 GCKMediaQueue。
- Parameters
- 
  cacheSize The cache size. Must be nonzero. maxFetchCount The maxiumum fetch count with minimum being 1. 
| - (void) addDelegate: | (id< GCKMediaQueueDelegate >) | delegate | 
向此对象的委托列表添加委托。
- Parameters
- 
  delegate The delegate to add. The delegate will be retained until removeDelegate: is called. 
| - (void) removeDelegate: | (id< GCKMediaQueueDelegate >) | delegate | 
从此对象的委托列表中移除委托。
- Parameters
- 
  delegate The delegate to remove. 
| - (nullable GCKMediaQueueItem *) itemAtIndex: | (NSUInteger) | index | 
返回队列中给定索引处的媒体队列项,或者安排从接收器提取该媒体队列项(如果该项当前不在缓存中)。
- Parameters
- 
  index The index of the item to fetch. 
- 返回
- 位于指定索引中的项,如果该项当前不在缓存中,则为 nil,但将被异步获取。
| - (nullable GCKMediaQueueItem *) itemAtIndex: | (NSUInteger) | index | |
| fetchIfNeeded: | (BOOL) | fetch | |
返回队列中给定索引处的媒体队列项,或者视需要安排从接收器提取媒体项(如果媒体项当前不在缓存中)。
- Parameters
- 
  index The index of the item to fetch. fetch Whether the item should be fetched from the receiver if it is not currently in the cache. 
- 返回
- 位于指定索引中的项,如果此项当前不在缓存中,则返回 nil。
| - (GCKMediaQueueItemID) itemIDAtIndex: | (NSUInteger) | index | 
返回队列中指定索引处的项 ID。
- 返回
- 指定索引中的项 ID,如果索引无效,则为 kGCKMediaQueueInvalidItemID。
| - (NSInteger) indexOfItemWithID: | (GCKMediaQueueItemID) | itemID | 
在队列中查找队列项的索引。
- Parameters
- 
  itemID The queue item ID. 
- 返回
- 队列中的项的索引(即基本位置),如果队列中没有此类项,则为 NSNotFound。
| - (void) reload | 
重新加载队列。
系统会刷新缓存,并从接收器中重新获取项 ID 列表。
| - (void) clear | 
清空队列,移除所有元素并清除缓存。
房源详情
| 
 | readnonatomicassign | 
当前在队列中的项数。
| 
 | readnonatomicassign | 
缓存大小。
| 
 | readnonatomicassign | 
当前位于缓存中的队列项数量。