It is said that the system built-in multimedia features support SRT, the other subtitles, such as the old weeks of testing several forms of subtitles can be loaded.
SRT subtitles is the simplest subtitle structure, even you can use Notepad to make, is divided into several lines to write.
The first line is the title of the number, should be starting from 1, anyway the tool generated SRT are numbered from 1 onwards;
The second line is the start time and end time of the caption, separated by a "--";
The third line is the subtitle content.
such as this:
-xx:Geneva:Panax Notoginseng,933-xx:Geneva: $,366While procured the wind and talking about the theory of blame +xx:Geneva: $,366-xx:Geneva: $,599 -xx:Geneva: $, --xx:Geneva: the, -To the celestial fluttering
The caption numbered 19 is blank, so the third line has no content.
OK, here's how to load an external SRT subtitle.
The first step: Create a MediaSource and then associate the MediaSource instance with the MediaElement control so that it can be played on the interface.
Fileopenpicker Picker =NewFileopenpicker (); Picker. Filetypefilter.add (". mkv"); Picker. Filetypefilter.add (". mp4"); StorageFile file=awaitPicker. Picksinglefileasync (); if(File! =NULL) {MediaSource ms=mediasource.createfromstoragefile (file); Me. Tag=MS; Me. Setplaybacksource (MS); }
The second step is to load the caption file, then create the Timedtextsource object and add it to the Mediasource.externaltimedtextsources attribute, which is a list with type Timedtextsource. One more subtitle track per Timedtextsource object added.
MediaSource mdsrc = Me. Tag asMediaSource; Fileopenpicker Picker=NewFileopenpicker (); Picker. Filetypefilter.add (". SRT"); StorageFile Srtfile=awaitPicker. Picksinglefileasync (); if(Srtfile! =NULL) {Irandomaccessstream stream=awaitSrtfile. OpenReadAsync (); Timedtextsource txtsrc=Timedtextsource.createfromstream (stream); Mdsrc. Externaltimedtextsources.clear (); Mdsrc. Externaltimedtextsources.add (TXTSRC); }
So it's done. If the video file has built-in captions, the method is the same, except that the video file itself is specified when the Timedtextsource object is created, and if it is an external caption, the caption file is specified.
Run the application, open video playback First, and then select the subtitle file. When a valid caption file is added, an open caption button appears in the control bar of the MediaElement control.
Then, click this button to select the loaded caption, or close the caption.
Finally, subtitles can be displayed in the video.
OK, the old week has a severe cold for two days, and now a little better, write a blog post.
Sample code download.
"Win 10 App development" Loading external SRT subtitles