GCKMediaInformation initWithContentID 已弃用警告

GCKMediaInformation initWithContentID is deprecated warning

在构建 GCKMediaInformation 时我收到此警告:

'initWithContentID:streamType:contentType:metadata:streamDuration:mediaTracks:textTrackStyle:customData:' is deprecated: Use GCKMediaInformationBuilder to initialize GCKMediaInformation objects.

这是我的方法:

GCKMediaInformation* mediaInfo = [[GCKMediaInformation alloc]
    initWithContentID:[self.chromecastUrl absoluteString] // WARNING ON THIS LINE
           streamType:self.videoPlayer.isLive ? GCKMediaStreamTypeLive
                                              : GCKMediaStreamTypeBuffered
          contentType:@"application/dash+xml"
             metadata:metadata
       streamDuration:duration
          mediaTracks:nil
       textTrackStyle:nil
           customData:customData];

如何传递?

以下是我通过 GCKMediaInformationBuilder 构建媒体信息来传递该警告的方法:

GCKMediaInformationBuilder *builder =
[[GCKMediaInformationBuilder alloc] initWithContentURL:self.chromecastUrl];
builder.contentType = @"application/dash+xml";
builder.streamType = self.videoPlayer.isLive ? GCKMediaStreamTypeLive : GCKMediaStreamTypeBuffered;
builder.metadata = metadata;
builder.streamDuration = duration;
builder.customData = customData;
// set all other desired properties...

// then build the GCKMediaInformation with build method
GCKMediaInformation *mediaInfo = [builder build];

希望对您有所帮助。

如果有人正在寻找 Swift 版本,就在这里。

let builder = GCKMediaInformationBuilder()

builder.contentType = "application/dash+xml"
builder.streamType = self.videoPlayer.isLive ? .live : .buffered
builder.metadata = metadata
builder.streamDuration = duration
builder.customData = customData
// set all other desired properties...

// then build the GCKMediaInformation with build method
let mediaInfo = builder.build()