Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

iOS Sdk Google Chromecast Subtitles

This is how I have implemented to show subtitles using a Google Chromecast device. But the subtitle doesnt appear. Do I have to make changes in 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)

//[END MEDIA]

like image 906
Taimur Ajmal Avatar asked Dec 16 '15 06:12

Taimur Ajmal


2 Answers

In the subtitlesTrack assignment, try setting contentType to "text/vtt", not "subtitles". From the working example declaration in the 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)

It also appears that the code above does not call setActiveTrackIds, like so:

mediaControlChannel?.setActiveTrackIDs([1])

This function call sets the track with ID 1 to active.

like image 194
Cassie Avatar answered Oct 02 '22 20:10

Cassie


I was calling wrong function for MediaControlChannel. For Subtitles a different function has to be called. This function was never used In Google APIs documentation or anywhere in sample codes. That would be great Help if Google can update a sample project using GCKMediaTrack for Text , Audio and Videos. Also, post some examples for casting Subtitles stream.

Heres the function!

self.mediaControlChannel!.loadMedia(mediaInformation, autoplay: true, playPosition: 0, activeTrackIDs: tracks)
like image 41
Taimur Ajmal Avatar answered Oct 02 '22 20:10

Taimur Ajmal