2

We have successfully configured Subtitles/Captions in Azure Media Player which plays media on the Web side.

But, how do we configure the same for playing the media managed by AMS in iOS for Native AVPlayer? We know that captions/subtitles can be played in native iOS player with Sidecar WebVTT file, but is the "transcript.vtt" file generated by AMS, the Sidecar WebVTT file ?

If not, how do we generate the sidecar WebVTT file?

We have implemented the code as below with Media file being accessed from AMS link and a locally downloaded transcript.vtt file, but it fails.

[EDITED : 20200413]

However, when we have local media file and local transcript.vtt file, or when we directly access the media file in the media storage account (https://mediastorageaccount.blob.core.windows.net/container/file.mp4) it works fine. But, when we access the encoded file from the link generated by AMS Transform (https://mediaservice-inct.streaming.media.azure.net/788888-6666-4444-aaaa-823422j218/file.ism/manifest(format=m3u8-cmaf)) it fails.

What is wrong here?

func playVideo()

{ let strUrl = "https://mediaservice-inct.streaming.media.azure.net/79510-6eb-340-a90-824218/German-FAST_Lesson-2-Dialog.ism/manifest(format=m3u8-cmaf)"

    localVideoAsset = AVURLAsset(url: URL(string: strUrl)!)

    //We have to add tracks in AVMutableComposition same like bellow

    //First we have to add video track on AVMutableComposition
    let videoTrack = videoPlusSubtitles.addMutableTrack(withMediaType: .video, preferredTrackID: kCMPersistentTrackID_Invalid)

    do{
        guard localVideoAsset!.tracks.count > 0 else{
            // error msg
            return
        }

        try? videoTrack?.insertTimeRange(CMTimeRangeMake(start: CMTime.zero, duration: localVideoAsset!.duration),
                                         of:localVideoAsset!.tracks(withMediaType: .video)[0],
                                         at: seconds)
    }


    //After that we have to add subtitle track in AVMutableComposition
    if isEnglishSubtitle {
        setSubtitleTrack(subtitle: "transcript")

    }else{
        setSubtitleTrack(subtitle: "transcript_tr")
    }



    //After set the video track and subtitle track we have to set in the player same like bellow
    player = AVPlayer(playerItem: AVPlayerItem(asset: videoPlusSubtitles))

    playerLayer.removeFromSuperlayer()
    playerLayer = AVPlayerLayer(player: player)
    playerLayer.frame = self.videoView.bounds
    playerLayer.videoGravity = .resizeAspect
    self.videoView.layer.addSublayer(playerLayer)

    player.play()

}

func setSubtitleTrack(subtitle : String){ print(subtitle) print(seconds)

    //Here we have to check if any pre track available. If available then we have to remove it same like bellow
    if subtitleTrack != nil{
        videoPlusSubtitles.removeTrack(subtitleTrack!)
    }


    //We have to get subtitle file from path same like bellow
    let subtitleAsset = AVURLAsset(url: Bundle.main.url(forResource: subtitle, withExtension: ".vtt")!)

    // And we have to add new track from here
    subtitleTrack = videoPlusSubtitles.addMutableTrack(withMediaType: .text, preferredTrackID: kCMPersistentTrackID_Invalid)
    do{
        guard subtitleAsset.tracks.count > 0 else{
            //error msg
            return
        }

        try? subtitleTrack?.insertTimeRange(CMTimeRangeMake(start: CMTime.zero, duration: localVideoAsset!.duration),
                                            of:subtitleAsset.tracks(withMediaType: .text)[0],
                                            at: seconds)
    }

}
amsDeveloper
  • 177
  • 4
  • 14

1 Answers1

0

I suspect the issue is not caused by the AMS stream. To double check, you may want to try using another stream HLS(e.g. try a HLS provided by Apple). Apple has specific requirements for playing VTT in AVPlayer. I've included an Apple doc link which has a lot of examples on streaming, and other links that may be helpful:

https://developer.apple.com/streaming/examples/

How to add external .vtt subtitle file to AVPlayerViewController in tvOS

AVUrlAsset and WebVTTs

Henry T
  • 38
  • 7
  • Thanks for sharing! I am now getting following error.. "External WebVTT Example[4210:121198] [] nw_endpoint_flow_copy_multipath_subflow_counts Called on non-Multipath connection" when tried with HLS. Any clue what needs to be done? – amsDeveloper Mar 31 '20 at 01:15
  • Please see the [EDITED : 20200413] note in the description. – amsDeveloper Apr 13 '20 at 07:52