iOS SDK Google Chromecast 字幕
iOS Sdk Google Chromecast Subtitles
这就是我使用 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)
//[结束媒体]
在 subtitlesTrack 分配中,尝试将 contentType 设置为 "text/vtt",而不是 "subtitles"。来自 iOS Sender Guide、
中的工作示例声明
let captionsTrack = GCKMediaTrack(identifier: 1, contentIdentifier:
"https://commondatastorage.googleapis.com/gtv-videos-bucket/sample/" +
"DesigningForGoogleCast-en.vtt", contentType: "text/vtt", type: GCKMediaTrackType.Text,
textSubtype: GCKMediaTextTrackSubtype.Captions, name: "English Captions",
languageCode: "en", customData: nil)
上面的代码似乎也没有调用 setActiveTrackIds
,像这样:
mediaControlChannel?.setActiveTrackIDs([1])
此函数调用将 ID 为 1 的轨道设置为活动状态。
我为 MediaControlChannel 调用了错误的函数。对于字幕,必须调用不同的函数。此函数从未在 Google API 文档或示例代码中的任何地方使用过。如果 Google 可以使用 GCKMediaTrack 为文本、音频和视频更新示例项目,那将是很好的帮助。
此外,post 投射字幕流的一些示例。
这是函数!
self.mediaControlChannel!.loadMedia(mediaInformation, autoplay: true, playPosition: 0, activeTrackIDs: tracks)
这就是我使用 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)
//[结束媒体]
在 subtitlesTrack 分配中,尝试将 contentType 设置为 "text/vtt",而不是 "subtitles"。来自 iOS Sender Guide、
中的工作示例声明let captionsTrack = GCKMediaTrack(identifier: 1, contentIdentifier:
"https://commondatastorage.googleapis.com/gtv-videos-bucket/sample/" +
"DesigningForGoogleCast-en.vtt", contentType: "text/vtt", type: GCKMediaTrackType.Text,
textSubtype: GCKMediaTextTrackSubtype.Captions, name: "English Captions",
languageCode: "en", customData: nil)
上面的代码似乎也没有调用 setActiveTrackIds
,像这样:
mediaControlChannel?.setActiveTrackIDs([1])
此函数调用将 ID 为 1 的轨道设置为活动状态。
我为 MediaControlChannel 调用了错误的函数。对于字幕,必须调用不同的函数。此函数从未在 Google API 文档或示例代码中的任何地方使用过。如果 Google 可以使用 GCKMediaTrack 为文本、音频和视频更新示例项目,那将是很好的帮助。 此外,post 投射字幕流的一些示例。
这是函数!
self.mediaControlChannel!.loadMedia(mediaInformation, autoplay: true, playPosition: 0, activeTrackIDs: tracks)