如何从隔离存储中打开媒体播放器 WebVTT 字幕

Posted

技术标签:

【中文标题】如何从隔离存储中打开媒体播放器 WebVTT 字幕【英文标题】:How to open Media Player WebVTT caption from isolated storage 【发布时间】:2015-01-04 20:04:50 【问题描述】:

我在 Wp8 c# 上有 mp4+vtt 字幕视频播放器项目。我在看 Microsoft.PlayerFramework.MediaPlayer 和 WebVTTPlugin,它的作品很完美: https://playerframework.codeplex.com/wikipage?title=Closed%20Captions%3a%20WebVTT 我使用此代码并且工作完美。但是我运气不好,我的项目 .vtt 字幕文件有“,”十进制分隔符,这意味着我的应用程序崩溃我需要下载字幕并将所有“,”替换为“。”并保存隔离存储,我处理它,但我无法将字幕源设置为隔离存储,因为隔离存储没有 uri。我知道我说不好,我用例子来说明:

我的标题: (http://dizilab.com/captions/chuck/sezon-1/tr/2.vtt?v=5.2)

1 00:00:06,600 --> 00:00:10,900 梅尔哈巴。贝尼姆·阿德姆查尔斯·巴托夫斯基, ama bana Chuck diyebilirsiniz。

2 00:00:11,323 --> 00:00:12,711 本拉尔贝尼姆 ayakkabılarım。

3 00:00:12,771 --> 00:00:14,209 Bu da beim hayatım。

4 00:00:14,249 --> 00:00:19,042 Casuslar, araba takipleri, bilgisayar çalan ninjalar ve günü kurtaran ben.

它的真正标题是:

WEBVTT 文件 1 00:00:06.600 --> 00:00:10.900 梅哈巴。贝尼姆阿迪姆 Charles Bartowski,ama bana Chuck diyebilirsiniz。

2 00:00:11.323 --> 00:00:12.711 Bunlar benim ayakkabılarım.

3 00:00:12.771 --> 00:00:14.209 Bu da beim hayatım.

4 00:00:14.249 --> 00:00:19.042 Casuslar, araba takipleri, bilgisayar çalan ninjalar ve günü kurtaran ben.

它是代码:

using Microsoft.PlayerFramework.WebVTT;
using System.IO.IsolatedStorage;
using System.IO;
using System.Threading.Tasks;
using Microsoft.PlayerFramework;

namespace PanoramaApp1

    public partial class MainPage : PhoneApplicationPage
    
        // Constructor
        public string alinanveri="";
        public MainPage()
        
            InitializeComponent();              

            Microsoft.PlayerFramework.MediaPlayer player =new Microsoft.PlayerFramework.MediaPlayer(); 
            Microsoft.PlayerFramework.WebVTT.WebVTTPlugin webvttPlugin = new WebVTTPlugin();
            Microsoft.PlayerFramework.Caption caption = new Microsoft.PlayerFramework.Caption(); 
            player.IsCaptionSelectionVisible = true;  
            player.Plugins.Add(webvttPlugin);
            altyazikaydet("http://dizilab.com/captions/chuck/sezon-1/tr/2.vtt?v=5.2");
            IsolatedStorageFile kayitliDepo = IsolatedStorageFile.GetUserStoreForApplication();

            var okuyucu = new StreamReader(new IsolatedStorageFileStream("altyazi.vtt", FileMode.Open, kayitliDepo));
            caption.Source = new Uri("i cant use here for access isostorage"); // url points to sample.vtt file

            caption.Description = "Türkçe";            
            player.AvailableCaptions.Add(caption);
            player.SelectedCaption = player.AvailableCaptions.FirstOrDefault();
            LayoutRoot.Children.Add(player);

             player.Source = new Uri("https://redirector.googlevideo.com/videoplayback?requiressl=yes&shardbypass=yes&cmbypass=yes&id=eafe5f42d368b2e0&itag=18&source=picasa&cmo=secure_transport%3Dyes&ip=0.0.0.0&ipbits=0&expire=1420976098&sparams=requiressl,shardbypass,cmbypass,id,itag,source,ip,ipbits,expire&signature=6E257266C2AAADDFC3260B0AADE603F7E421E130.A933FF8365247DEC72A34B71B02FA3B13C57F291&key=lh1", UriKind.RelativeOrAbsolute); // url points to sample.mp4 fil
        

        private  async void altyazikaydet(string altyaziurl)
        
            try
            

            HttpWebRequest request = (HttpWebRequest)HttpWebRequest.Create(altyaziurl);


            using (var response = (HttpWebResponse)(await Task<WebResponse>.Factory.FromAsync(request.BeginGetResponse, request.EndGetResponse, null)))
            
                using (var responseStream = response.GetResponseStream())
                
                    using (var sr = new StreamReader(responseStream))
                    

                        alinanveri = await sr.ReadToEndAsync();
                    
                
            
                IsolatedStorageFile file = IsolatedStorageFile.GetUserStoreForApplication();
                StreamWriter yazici = new StreamWriter(new IsolatedStorageFileStream("altyazi.vtt", FileMode.Create, file));

                string x=alinanveri;
                x=x.Replace(",0",".0");
                x=x.Replace(",1",".1");
                x=x.Replace(",2",".2");
                x=x.Replace(",3",".3");
                x=x.Replace(",4",".4");
                x=x.Replace(",5",".5");
                x=x.Replace(",6",".6");
                x=x.Replace(",7",".7");
                x=x.Replace(",8",".8");
                x=x.Replace(",9",".9");
                x = "WEBVTT FILE" + Environment.NewLine + x;
                yazici.WriteLine(x);                
                yazici.Close();
                IsolatedStorageFile kayitliDepo = IsolatedStorageFile.GetUserStoreForApplication();

                StreamReader okuyucu = new StreamReader(new IsolatedStorageFileStream("altyazi.vtt", FileMode.Open, kayitliDepo));

                    string line;
                    while ((line = okuyucu.ReadLine()) != null)
                    
                        MessageBox.Show(line);
                    



            
            catch
            

            
        

【问题讨论】:

【参考方案1】:

我在 Windows UWP 中遇到了同样的问题。 player.Source 允许绝对本地 URI,但 webvtt 插件不允许。

最后,我发现了如何让它发挥作用:

using System.IO;

var caption = new Caption

    Description = "whatever",
    Source = new Uri(Path.Combine("ms-appdata:///Local/", "test.vtt"))
;

Player.AvailableCaptions.Add(caption);
Player.SelectedCaption = Player.AvailableCaptions.FirstOrDefault();

【讨论】:

【参考方案2】:

不确定这是否有效,但来自this article,你可以试试这个

string fullpath = "";
using (IsolatedStorageFile kayitliDepo = IsolatedStorageFile.GetUserStoreForApplication())
     
    IsolatedStorageFileStream stream = kayitliDepo.OpenFile("altyazi.vtt", FileMode.Open,FileAccess.Read);
    fullpath = stream.Name;

caption.Source = new Uri(Name,Urikind.Absolute); // url points to sample.vtt file
caption.Description = "Türkçe";            
player.AvailableCaptions.Add(caption);
player.SelectedCaption = player.AvailableCaptions.FirstOrDefault();

【讨论】:

以上是关于如何从隔离存储中打开媒体播放器 WebVTT 字幕的主要内容,如果未能解决你的问题,请参考以下文章

阿里云 Aliplayer高级功能介绍:多字幕

Mozilla Firefox 中缺少 CC 按钮

我下载了一些视频,但字幕是webvtt格式的,我用的是暴风影音,因此看不到字幕。请问有啥办法可以

分段 WebVTT 不适用于 Chromecast

如果代码是用 PHP 生成的,WEBVTT 字幕不显示

使用 WebVTT 未显示字幕