Jadi saya telah berhasil memutar video di Chromecast. Tapi hanya satu per satu. Saya sudah mencoba mencari cara untuk menambah antrian secara terprogram. Idenya adalah untuk terus memutar video sepanjang hari. Dalam kode di bawah ini "playthisvideo()" secara acak mengembalikan string yang berisi http://.....mp4< /a> . Saya telah melihat dokumentasi Google, terlalu kabur atau saya hanya tidak memahaminya. Dan sepertinya saya tidak dapat menemukan contoh yang akan menuntun saya untuk mengikuti.

func castthevideo() {
    let metadata = GCKMediaMetadata()
    metadata.setString("Los Simpsons", forKey: kGCKMetadataKeyTitle)
    metadata.setString ("Barista: ¿Cómo tomas tu café? " +
        " Yo: Muy, muy en serio.",
                        forKey: kGCKMetadataKeySubtitle)
    metadata.addImage(GCKImage(url: URL(string: "https://m.media-amazon.com/images/M/MV5BYjFkMTlkYWUtZWFhNy00M2FmLThiOTYtYTRiYjVlZWYxNmJkXkEyXkFqcGdeQXVyNTAyODkwOQ@@._V1_.jpg")!,
                               width: 480,
                               height: 360))
    let PTV = playthisvideo()
    let url = URL.init(string: PTV)
    print ("******  ", PTV)
    guard let mediaURL = url else {
        print("******  invalid mediaURL")
        return }
    //let mediaInfoBuilder = GCKMediaInformationBuilder.init(contentURL: mediaURL)
    let mediaInfoBuilder = GCKMediaInformationBuilder.init(contentURL: mediaURL)
    mediaInfoBuilder.streamType = GCKMediaStreamType.none;
    mediaInfoBuilder.contentType = "video/mp4"
    mediaInfoBuilder.metadata = metadata;
    let  mediaInformation = mediaInfoBuilder.build()
    if let request = sessionManager.currentSession?.remoteMediaClient?.loadMedia(mediaInformation) { request.delegate = self }

    GCKCastContext.sharedInstance().presentDefaultExpandedMediaControls()

}

Func castanthor(denganMenambahkan menambahkan: Bool) {

    let PTV = playthisvideo()
    let url = URL.init(string: PTV)
    guard let mediaURL = url else {
        print("invalid mediaURL")
        return
    }

    myNSNumber = (1 as NSNumber)
    if let remoteMediaClient = GCKCastContext.sharedInstance().sessionManager.currentCastSession?.remoteMediaClient {
        let builder = GCKMediaQueueItemBuilder()
        builder.mediaInformation = selectedItem.mediaInfo
        builder.autoplay = true
        builder.preloadTime = 3
        let item = builder.build
        if remoteMediaClient.mediaStatus != nil, appending {
            let request = remoteMediaClient.queueInsert(item(), beforeItemWithID: kGCKMediaQueueInvalidItemID)
            request.delegate = self
        } else {
            let options = GCKMediaQueueLoadOptions()
            options.repeatMode = remoteMediaClient.mediaStatus?.queueRepeatMode ?? .off
            let request = castSession.remoteMediaClient?.queueLoad([item()], with: options)
            request?.delegate = self
        }
    }}
2
Brian M 11 Maret 2019, 01:12

1 menjawab

Jawaban Terbaik
var mediaItems = [GCKMediaQueueItem]()
var urls = // Array of only audio and videos
for index in 0..<urls.count {
    let builder = GCKMediaQueueItemBuilder()
    let mediaInfoBuilder = GCKMediaInformationBuilder.init(contentURL: urls[i])
    mediaInfoBuilder.streamType = GCKMediaStreamType.none;
    mediaInfoBuilder.contentType = "video/mp4"
    mediaInfoBuilder.metadata = metadata;
    let mediaInformation = mediaInfoBuilder.build()
    builder.mediaInformation = mediaInformation
    builder.autoplay = true
    builder.preloadTime = 3
    let item = builder.build
    mediaItems.append(item)
}

if let remoteMediaClient = GCKCastContext.sharedInstance().sessionManager.currentCastSession?.remoteMediaClient {
    let loadOptions = GCKMediaQueueLoadOptions()
    loadOptions.repeatMode = .all
    loadOptions.startPosition = 0
    remoteMediaClient.queueLoadItems(mediaItems, withOptions:loadOptions)
}
2
Sachin Vas 11 Maret 2019, 06:05