首页
学习
活动
专区
圈层
工具
发布
首页
学习
活动
专区
圈层
工具
MCP广场
社区首页 >问答首页 >如何从隔离存储中打开媒体播放器WebVTT字幕

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

Stack Overflow用户
提问于 2015-01-04 20:04:50
回答 2查看 728关注 0票数 0

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

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

00:00:06,600 -> 00:00:10,900 Merhaba。本尼姆广告ım查尔斯巴托斯基,美国巴纳恰克迪耶比尔斯尼茨。

2:00:11,323-> 00:00:12,711 Bunlar benim ayakkabılarım.

3:00:12,771-> 00:00:14,209 Bu da benim hayatım.

下午4: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 Merhaba。本尼姆广告ım查尔斯巴托斯基,美国巴纳恰克迪耶比尔斯尼茨。 2:00:11.323-> 00:00:12.711 Bunlar ayakkabılarım. 3:00:12.771 --> 00:00:14.209 Bu da benim hayatım. 下午4:00:14.249-> 00:00:19.042 Casuslar,araba takipleri,bilgisayar alan ninjalar ve günükurtaran ben。

这是密码:

代码语言:javascript
运行
复制
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
            {

            }
        }
EN

回答 2

Stack Overflow用户

回答已采纳

发布于 2016-05-13 20:10:24

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

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

代码语言:javascript
运行
复制
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();
票数 1
EN

Stack Overflow用户

发布于 2015-01-20 13:21:53

不确定这是否有效,但是在这篇文章中,您可以尝试一下

代码语言:javascript
运行
复制
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();
票数 1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/27769778

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档