这就是我使用Google Chromecast设备显示字幕的方法.但副标题并没有出现.我是否必须在Chromecast API中进行更改?
var subtitleName:String = "" var subtitleLink:String = "" var subtitleType:String = "" var subtitleCode:String = "" if let _ = self.selectedSubtitle { let subtitleIndex: Int = self.selectedSubtitle! - 1 subtitleName = self.videoObject.subtitles![subtitleIndex].language! subtitleLink = self.videoObject.subtitles![subtitleIndex].link! subtitleLink = subtitleLink + ".vtt" subtitleType = self.videoObject.subtitles![subtitleIndex].type! subtitleCode = (self.subtitleLanguages.objectAtIndex(subtitleIndex) as! ICFLanguageObject).iso_639_3! as String } print("\n\nName: \(subtitleName),\n Link:\(subtitleLink) \n Type: \(subtitleType)\n Code: \(subtitleCode)\n\n") //Values Printed on console //Name: ara, //Link:http://a**************c.vtt //Type: subtitles //Code: ara let subtitlesTrack = GCKMediaTrack(identifier: chromeCast_SubtitleID, contentIdentifier:subtitleLink, contentType: "text/vtt", type: GCKMediaTrackType.Text, textSubtype: GCKMediaTextTrackSubtype.Captions, name: subtitleName, languageCode: subtitleCode, customData: nil) // Set Progress let time: Double = duration * (value - minValue) / (maxValue - minValue) let progress: NSTimeInterval = NSString(format: "%f", (time)).doubleValue let textTrackStyle = GCKMediaTextTrackStyle.createDefault() textTrackStyle.foregroundColor = GCKColor(CSSString: "#FF000080") textTrackStyle.fontFamily = "serif" styleChangeRequestID = (mediaControlChannel?.setTextTrackStyle(textTrackStyle))! print(styleChangeRequestID) mediaControlChannel?.setActiveTrackIDs([chromeCast_SubtitleID]) mediaControlChannel?.setTextTrackStyle(textTrackStyle) deviceManager?.setVolume(0.5) let tracks = [subtitlesTrack] let mediaInformation = GCKMediaInformation( contentID:self.playbackObject.playbackURL(), streamType: GCKMediaStreamType.None, contentType: self.playbackObject.playbacktype(), metadata: metadata, streamDuration: progress, mediaTracks: tracks, textTrackStyle: textTrackStyle, customData: nil ) deviceManager?.setVolume(0.5) mediaControlChannel!.loadMedia(mediaInformation, autoplay: true, playPosition: progress)
// [结束媒体]