private void PlayIconVideoOnClick(object sender, EventArgs e) { try { if (PlayIconVideo.Tag.ToString() == "Play") { MediaMetadataRetriever retriever; if (PathStory.Contains("http")) { StoryVideoView.SetVideoURI(Uri.Parse(PathStory)); retriever = new MediaMetadataRetriever(); if ((int)Build.VERSION.SdkInt >= 14) { retriever.SetDataSource(PathStory, new Dictionary <string, string>()); } else { retriever.SetDataSource(PathStory); } } else { var file = Uri.FromFile(new File(PathStory)); StoryVideoView.SetVideoPath(file.Path); retriever = new MediaMetadataRetriever(); //if ((int)Build.VERSION.SdkInt >= 14) // retriever.SetDataSource(file.Path, new Dictionary<string, string>()); //else // retriever.SetDataSource(file.Path); retriever.SetDataSource(file.Path); } StoryVideoView.Start(); Duration = Long.ParseLong(retriever.ExtractMetadata(MetadataKey.Duration)); retriever.Release(); StoriesProgress.Visibility = ViewStates.Visible; StoriesProgress.SetStoriesCount(1); // <- set stories StoriesProgress.SetStoryDuration(Duration); // <- set a story duration StoriesProgress.StartStories(); // <- start progress PlayIconVideo.Tag = "Stop"; PlayIconVideo.SetImageResource(Resource.Drawable.ic_stop_white_24dp); } else { StoriesProgress.Visibility = ViewStates.Gone; StoriesProgress.Pause(); StoryVideoView.Pause(); PlayIconVideo.Tag = "Play"; PlayIconVideo.SetImageResource(Resource.Drawable.ic_play_arrow); } } catch (Exception ex) { Console.WriteLine(ex); } }
private void PlayIconVideoOnClick(object sender, EventArgs e) { try { switch (PlayIconVideo?.Tag?.ToString()) { case "Play": { MediaMetadataRetriever retriever; if (PathStory.Contains("http")) { StoryVideoView.SetVideoURI(Uri.Parse(PathStory)); retriever = new MediaMetadataRetriever(); switch ((int)Build.VERSION.SdkInt) { case >= 14: retriever.SetDataSource(PathStory, new Dictionary <string, string>()); break; default: retriever.SetDataSource(PathStory); break; } } else { var file = Uri.FromFile(new File(PathStory)); StoryVideoView.SetVideoPath(file?.Path); retriever = new MediaMetadataRetriever(); //if ((int)Build.VERSION.SdkInt >= 14) // retriever.SetDataSource(file.Path, new Dictionary<string, string>()); //else // retriever.SetDataSource(file.Path); retriever.SetDataSource(file?.Path); } StoryVideoView.Start(); Duration = Long.ParseLong(retriever.ExtractMetadata(MetadataKey.Duration) ?? string.Empty); retriever.Release(); StoriesProgress.Visibility = ViewStates.Visible; StoriesProgress.SetStoriesCount(1); // <- set stories StoriesProgress.SetStoryDuration(Duration); // <- set a story duration StoriesProgress.StartStories(); // <- start progress PlayIconVideo.Tag = "Stop"; PlayIconVideo.SetImageResource(Resource.Drawable.ic_stop_white_24dp); break; } default: { StoriesProgress.Visibility = ViewStates.Gone; StoriesProgress.Pause(); StoryVideoView.Pause(); if (PlayIconVideo != null) { PlayIconVideo.Tag = "Play"; PlayIconVideo.SetImageResource(Resource.Drawable.ic_play_arrow); } break; } } } catch (Exception ex) { Methods.DisplayReportResultTrack(ex); } }