예제 #1
0
        private static async Task <TimeSpan?> GetByContentTypeAsync(Uri url)
        {
            if (url == null)
            {
                throw new ArgumentNullException();
            }

            // Get content type
            try {
                HttpWebRequest req = WebRequest.CreateHttp(url);
                req.UserAgent = Shared.UserAgent;
                req.Method    = "HEAD";
                using (var resp = await req.GetResponseAsync()) {
                    switch (resp.ContentType)
                    {
                    case "application/vnd.apple.mpegurl":
                        return(await HLS.GetPlaylistDurationAsync(url));

                    case "video/mp4":
                        return(await MP4.GetDurationAsync(url));

                    default:
                        return(null);
                    }
                }
            } catch (WebException ex) when((ex.Response as HttpWebResponse)?.StatusCode == HttpStatusCode.NotFound)
            {
                throw new VideoNotFoundException(ex);
            }
        }
예제 #2
0
        private static async Task <TimeSpan?> GetByNameAsync(Uri url, string youTubeKey = null, ITwitchCredentials twitchCredentials = null)
        {
            if (url == null)
            {
                throw new ArgumentNullException();
            }

            if (url.AbsolutePath.EndsWith(".mp4", StringComparison.InvariantCultureIgnoreCase))
            {
                // Assume MP4
                return(await MP4.GetDurationAsync(url));
            }
            else if (url.AbsolutePath.EndsWith(".m3u8", StringComparison.InvariantCultureIgnoreCase))
            {
                // Assume HLS
                return(await HLS.GetPlaylistDurationAsync(url));
            }
            else if (url.Authority.EndsWith("vimeo.com"))
            {
                return(await Vimeo.GetDurationAsync(url));
            }
            else if (url.Authority.EndsWith("youtube.com") || url.Authority.EndsWith("youtu.be"))
            {
                return(youTubeKey == null
                    ? null
                    : await new YouTube(youTubeKey).GetDurationAsync(url));
            }
            else if (url.Authority.EndsWith("dailymotion.com") || url.Authority.EndsWith("dai.ly"))
            {
                return(await Dailymotion.GetDurationAsync(url));
            }
            else if (url.Authority.EndsWith("twitch.tv"))
            {
                return(await new Twitch(twitchCredentials).GetDurationAsync(url));
            }
            else if (url.Authority.EndsWith("soundcloud.com"))
            {
                return(await SoundCloud.GetDurationAsync(url));
            }
            else
            {
                return(null);
            }
        }
예제 #3
0
 void OnPlatformSelected(string name, MP4 mp4)
 {
     Debug.Log("menu \"" + name + "\" is selected");
     Debug.Log("video path:" + mp4.getLocalPath());
 }