2015-12-16 14 views
6

Ecco come ho implementato per mostrare i sottotitoli utilizzando un dispositivo Google Chromecast. Ma il sottotitolo non appare. Devo apportare modifiche all'API di Chromecast?iOS Sdk Google Chromecast Sottotitoli

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]

risposta

1

Stavo chiamando la funzione sbagliata per MediaControlChannel. Per i sottotitoli è necessario chiamare una funzione diversa. Questa funzione non è mai stata utilizzata nella documentazione delle API di Google o in alcuno dei codici di esempio. Sarebbe fantastico Aiutare se Google può aggiornare un progetto di esempio usando GCKMediaTrack per Testo, Audio e Video. Inoltre, pubblica alcuni esempi per trasmettere lo streaming dei sottotitoli.

Ecco la funzione!

self.mediaControlChannel!.loadMedia(mediaInformation, autoplay: true, playPosition: 0, activeTrackIDs: tracks) 
+1

ha funzionato con te @Taimur Ajmal? – Bkillnest

+0

Sì, ha funzionato Perfetto. –

2

Nell'assegnazione subtitlesTrack, provare a impostare contentType a "text/VTT", non "sottotitoli". Dalla dichiarazione esempio funzionante nel 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) 

Risulta inoltre che il codice di cui sopra non chiama setActiveTrackIds, in questo modo:

mediaControlChannel?.setActiveTrackIDs([1]) 

Questa chiamata funzione imposta la pista con ID 1 ad attivo.

+0

Ho provato e il suo ancora non funziona .. –

+0

Aggiornato la mia risposta con alcune ulteriori informazioni - vedere se la nuova soluzione funziona. – Cassie

+0

Grazie mille. Ho provato anche quello. ( –

Problemi correlati