当前位置:  开发笔记 > 编程语言 > 正文

iOS Sdk谷歌Chromecast字幕

如何解决《iOSSdk谷歌Chromecast字幕》经验,为你挑选了0个好方法。

这就是我使用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)

// [结束媒体]

推荐阅读
oDavid_仔o_880
这个屌丝很懒,什么也没留下!
DevBox开发工具箱 | 专业的在线开发工具网站    京公网安备 11010802040832号  |  京ICP备19059560号-6
Copyright © 1998 - 2020 DevBox.CN. All Rights Reserved devBox.cn 开发工具箱 版权所有