Archived
1
0

Video player debug

This commit is contained in:
Michael Gordeev
2018-10-03 20:18:16 +03:00
parent a23774275f
commit 8d09fc9a89
2 changed files with 119 additions and 59 deletions
+6 -3
View File
@@ -16,8 +16,8 @@
PointerEntered="UserControl_PointerEntered"> PointerEntered="UserControl_PointerEntered">
<Grid Background="White" Name="grid" Tapped="UserControl_Tapped"> <Grid Background="White" Name="grid" Tapped="UserControl_Tapped">
<MediaElement Width="0" Height="0" VerticalAlignment="Top" HorizontalAlignment="Right" Name="audioSource"/> <MediaElement Width="0" Height="0" VerticalAlignment="Top" HorizontalAlignment="Right" Name="audioSource" MediaOpened="videoSource_Opened" BufferingProgressChanged="videoSource_BufferingProgressChanged"/>
<MediaElement IsDoubleTapEnabled="False" CurrentStateChanged="videoSource_CurrentStateChanged" AutoPlay="False" Volume="0" Name="videoSource" AreTransportControlsEnabled="False" PosterSource="ms-appx:///Assets/videoThumbSample.png"/> <MediaElement IsDoubleTapEnabled="False" CurrentStateChanged="videoSource_CurrentStateChanged" AutoPlay="False" MediaOpened="videoSource_Opened" BufferingProgressChanged="videoSource_BufferingProgressChanged" Volume="0" Name="videoSource" AreTransportControlsEnabled="False" PosterSource="ms-appx:///Assets/videoThumbSample.png"/>
<controls1:LiveCaptions Player="{x:Bind videoSource}" Visibility="Collapsed"/> <controls1:LiveCaptions Player="{x:Bind videoSource}" Visibility="Collapsed"/>
@@ -98,7 +98,10 @@
<Grid Grid.Column="1"> <Grid Grid.Column="1">
<TextBlock Name="elapsedTime" Foreground="White" Text="[Elapsed]" VerticalAlignment="Bottom" HorizontalAlignment="Left" ToolTipService.ToolTip="Time elapsed"/> <TextBlock Name="elapsedTime" Foreground="White" Text="[Elapsed]" VerticalAlignment="Bottom" HorizontalAlignment="Left" ToolTipService.ToolTip="Time elapsed"/>
<TextBlock Name="remainingTime" Foreground="White" Text="[Remaining]" VerticalAlignment="Bottom" HorizontalAlignment="Right" ToolTipService.ToolTip="Time remaining"/> <TextBlock Name="remainingTime" Foreground="White" Text="[Remaining]" VerticalAlignment="Bottom" HorizontalAlignment="Right" ToolTipService.ToolTip="Time remaining"/>
<Slider PointerCaptureLost="seek_PointerCaptureLost" ValueChanged="seek_ValueChanged" Name="seek" VerticalAlignment="Top" ToolTipService.ToolTip="Seek" IsThumbToolTipEnabled="False" HorizontalAlignment="Stretch"/> <Grid VerticalAlignment="Top" Margin="0,18,0,0" Height="2">
<ProgressBar Background="#66FFFFFF" Foreground="LightGray" Name="bufferingLevel"/>
</Grid>
<Slider PointerCaptureLost="seek_PointerCaptureLost" ValueChanged="seek_ValueChanged" Name="seek" VerticalAlignment="Top" ToolTipService.ToolTip="Seek" IsThumbToolTipEnabled="False" Background="Transparent" HorizontalAlignment="Stretch"/>
</Grid> </Grid>
<StackPanel Grid.Column="2" Orientation="Horizontal"> <StackPanel Grid.Column="2" Orientation="Horizontal">
+111 -54
View File
@@ -67,6 +67,10 @@ namespace FoxTube
public event ObjectEventHandler SetFullSize; public event ObjectEventHandler SetFullSize;
public event ObjectEventHandler NextClicked; public event ObjectEventHandler NextClicked;
bool isMuxed = false;
bool audioReady = false;
bool videoReady = false;
CoreCursor cursorBackup = Window.Current.CoreWindow.PointerCursor; CoreCursor cursorBackup = Window.Current.CoreWindow.PointerCursor;
Point cursorPositionBackup; Point cursorPositionBackup;
@@ -129,7 +133,11 @@ namespace FoxTube
#region Retrieving info for CC and Media streams #region Retrieving info for CC and Media streams
//Loading streams //Loading streams
streamInfo = (await YouTube.GetUrisAsync(item.Id)).ToList(); streamInfo = (await YouTube.GetUrisAsync(item.Id)).ToList();
streamInfo.ForEach(x => Debug.WriteLine(x)); foreach (YouTubeQuality q in Enum.GetValues(typeof(YouTubeQuality)))
if (streamInfo.FindAll(x => x.VideoQuality == q).Count > 1)
streamInfo.RemoveAll(x => x.VideoQuality == q && !x.HasAudio);
streamInfo.ForEach(x => Debug.WriteLine($"{x.HasAudio}; {x.HasVideo}; {x.VideoQuality}; {x.AudioQuality}"));
foreach (YouTubeUri i in streamInfo) foreach (YouTubeUri i in streamInfo)
{ {
if (i.VideoQuality == YouTubeQuality.Quality2160P) if (i.VideoQuality == YouTubeQuality.Quality2160P)
@@ -258,11 +266,11 @@ namespace FoxTube
{ {
seek.Value = videoSource.Position.TotalSeconds; seek.Value = videoSource.Position.TotalSeconds;
seekIndicator.Value = seek.Value; seekIndicator.Value = seek.Value;
if (Math.Round(videoSource.Position.TotalSeconds, 1) != Math.Round(audioSource.Position.TotalSeconds, 1)) /*if (Math.Round(videoSource.Position.TotalSeconds, 1) != Math.Round(audioSource.Position.TotalSeconds, 1))
{ {
Debug.WriteLine($"Correcting tracks synchronization (Video track position: {videoSource.Position}; Audio track position: {audioSource.Position})"); Debug.WriteLine($"Correcting tracks synchronization (Video track position: {videoSource.Position}; Audio track position: {audioSource.Position})");
audioSource.Position = videoSource.Position; audioSource.Position = videoSource.Position;
} }*/
} }
void Elapsed() void Elapsed()
@@ -292,19 +300,19 @@ namespace FoxTube
{ {
double v = volume.Value; double v = volume.Value;
if (v == 0) if (v == 0)
muteBtn.Content = openVolume.Content = ""; muteBtn.Content = openVolume.Content = "\xE74F";
else if (v <= 25 && v > 0) else if (v <= 25 && v > 0)
muteBtn.Content = openVolume.Content = ""; muteBtn.Content = openVolume.Content = "\xE992";
else if (v <= 50 && v > 25) else if (v <= 50 && v > 25)
muteBtn.Content = openVolume.Content = ""; muteBtn.Content = openVolume.Content = "\xE993";
else if (v <= 75 && v > 50) else if (v <= 75 && v > 50)
muteBtn.Content = openVolume.Content = ""; muteBtn.Content = openVolume.Content = "\xE994";
else if (v > 75) else if (v > 75)
muteBtn.Content = openVolume.Content = ""; muteBtn.Content = openVolume.Content = "\xE995";
settings.Values["volume"] = volume.Value; settings.Values["volume"] = volume.Value;
audioSource.Volume = volume.Value * 0.01; audioSource.Volume = videoSource.Volume = volume.Value * 0.01;
} }
private void muteBtn_Click(object sender, RoutedEventArgs e) private void muteBtn_Click(object sender, RoutedEventArgs e)
@@ -352,82 +360,108 @@ namespace FoxTube
private void quality_SelectionChanged(object sender, SelectionChangedEventArgs e) private void quality_SelectionChanged(object sender, SelectionChangedEventArgs e)
{ {
//try try
{ {
videoSource.Pause(); videoSource.Pause();
audioSource.Source = null;
timecodeBackup = videoSource.Position.TotalSeconds; timecodeBackup = videoSource.Position.TotalSeconds;
audioReady = false;
videoReady = false;
switch((quality.SelectedItem as ComboBoxItem).Content) switch((quality.SelectedItem as ComboBoxItem).Content)
{ {
case "2160p": case "2160p":
videoSource.Source = streamInfo.First(x => x.VideoQuality == YouTubeQuality.Quality2160P).Uri; if(streamInfo.First(x => x.VideoQuality == YouTubeQuality.Quality2160P).HasAudio)
try { audioSource.Source = streamInfo.First(x => x.AudioQuality == YouTubeQuality.QualityHigh).Uri; } isMuxed = true;
catch else
{ {
try { audioSource.Source = streamInfo.First(x => x.AudioQuality == YouTubeQuality.QualityMedium).Uri; } isMuxed = false;
catch { audioSource.Source = streamInfo.First(x => x.AudioQuality == YouTubeQuality.QualityLow).Uri; } audioSource.Source = (streamInfo.Find(x => x.AudioQuality == YouTubeQuality.QualityHigh && !x.HasVideo) ??
streamInfo.Find(x => x.AudioQuality == YouTubeQuality.QualityMedium && !x.HasVideo) ??
streamInfo.Find(x => x.AudioQuality == YouTubeQuality.QualityLow && !x.HasVideo) ??
streamInfo.Find(x => x.HasAudio && !x.HasVideo)).Uri;
} }
videoSource.Source = streamInfo.First(x => x.VideoQuality == YouTubeQuality.Quality2160P).Uri;
break; break;
case "1080p": case "1080p":
videoSource.Source = streamInfo.First(x => x.VideoQuality == YouTubeQuality.Quality1080P).Uri; if (streamInfo.First(x => x.VideoQuality == YouTubeQuality.Quality1080P).HasAudio)
try { audioSource.Source = streamInfo.First(x => x.AudioQuality == YouTubeQuality.QualityHigh).Uri; } isMuxed = true;
catch else
{ {
try { audioSource.Source = streamInfo.First(x => x.AudioQuality == YouTubeQuality.QualityMedium).Uri; } isMuxed = false;
catch { audioSource.Source = streamInfo.First(x => x.AudioQuality == YouTubeQuality.QualityLow).Uri; } audioSource.Source = (streamInfo.Find(x => x.AudioQuality == YouTubeQuality.QualityHigh && !x.HasVideo) ??
streamInfo.Find(x => x.AudioQuality == YouTubeQuality.QualityMedium && !x.HasVideo) ??
streamInfo.Find(x => x.AudioQuality == YouTubeQuality.QualityLow && !x.HasVideo) ??
streamInfo.Find(x => x.HasAudio && !x.HasVideo)).Uri;
} }
videoSource.Source = streamInfo.First(x => x.VideoQuality == YouTubeQuality.Quality1080P).Uri;
break; break;
case "720p": case "720p":
videoSource.Source = streamInfo.First(x => x.VideoQuality == YouTubeQuality.Quality720P).Uri; if (streamInfo.First(x => x.VideoQuality == YouTubeQuality.Quality720P).HasAudio)
try { audioSource.Source = streamInfo.First(x => x.AudioQuality == YouTubeQuality.QualityHigh).Uri; } isMuxed = true;
catch else
{ {
try { audioSource.Source = streamInfo.First(x => x.AudioQuality == YouTubeQuality.QualityMedium).Uri; } isMuxed = false;
catch { audioSource.Source = streamInfo.First(x => x.AudioQuality == YouTubeQuality.QualityLow).Uri; } audioSource.Source = (streamInfo.Find(x => x.AudioQuality == YouTubeQuality.QualityHigh && !x.HasVideo) ??
streamInfo.Find(x => x.AudioQuality == YouTubeQuality.QualityMedium && !x.HasVideo) ??
streamInfo.Find(x => x.AudioQuality == YouTubeQuality.QualityLow && !x.HasVideo) ??
streamInfo.Find(x => x.HasAudio && !x.HasVideo)).Uri;
} }
videoSource.Source = streamInfo.First(x => x.VideoQuality == YouTubeQuality.Quality720P).Uri;
break; break;
case "480p": case "480p":
videoSource.Source = streamInfo.First(x => x.VideoQuality == YouTubeQuality.Quality480P).Uri; if (streamInfo.First(x => x.VideoQuality == YouTubeQuality.Quality480P).HasAudio)
try { audioSource.Source = streamInfo.First(x => x.AudioQuality == YouTubeQuality.QualityMedium).Uri; } isMuxed = true;
catch else
{ {
try { audioSource.Source = streamInfo.First(x => x.AudioQuality == YouTubeQuality.QualityHigh).Uri; } isMuxed = false;
catch { audioSource.Source = streamInfo.First(x => x.AudioQuality == YouTubeQuality.QualityLow).Uri; } audioSource.Source = (streamInfo.Find(x => x.AudioQuality == YouTubeQuality.QualityMedium && !x.HasVideo) ??
streamInfo.Find(x => x.AudioQuality == YouTubeQuality.QualityLow && !x.HasVideo) ??
streamInfo.Find(x => x.HasAudio && !x.HasVideo)).Uri;
} }
videoSource.Source = streamInfo.First(x => x.VideoQuality == YouTubeQuality.Quality480P).Uri;
break; break;
case "360p": case "360p":
videoSource.Source = streamInfo.First(x => x.VideoQuality == YouTubeQuality.Quality360P).Uri; if (streamInfo.First(x => x.VideoQuality == YouTubeQuality.Quality360P).HasAudio)
try { audioSource.Source = streamInfo.First(x => x.AudioQuality == YouTubeQuality.QualityMedium).Uri; } isMuxed = true;
catch else
{ {
try { audioSource.Source = streamInfo.First(x => x.AudioQuality == YouTubeQuality.QualityHigh).Uri; } isMuxed = false;
catch { audioSource.Source = streamInfo.First(x => x.AudioQuality == YouTubeQuality.QualityLow).Uri; } audioSource.Source = (streamInfo.Find(x => x.AudioQuality == YouTubeQuality.QualityMedium && !x.HasVideo) ??
streamInfo.Find(x => x.AudioQuality == YouTubeQuality.QualityLow && !x.HasVideo) ??
streamInfo.Find(x => x.HasAudio && !x.HasVideo)).Uri;
} }
videoSource.Source = streamInfo.First(x => x.VideoQuality == YouTubeQuality.Quality360P).Uri;
break; break;
case "240p": case "240p":
videoSource.Source = streamInfo.First(x => x.VideoQuality == YouTubeQuality.Quality240P).Uri; if (streamInfo.First(x => x.VideoQuality == YouTubeQuality.Quality240P).HasAudio)
try { audioSource.Source = streamInfo.First(x => x.AudioQuality == YouTubeQuality.QualityLow).Uri; } isMuxed = true;
catch else
{ {
try { audioSource.Source = streamInfo.First(x => x.AudioQuality == YouTubeQuality.QualityMedium).Uri; } isMuxed = false;
catch { audioSource.Source = streamInfo.First(x => x.AudioQuality == YouTubeQuality.QualityHigh).Uri; } audioSource.Source = (streamInfo.Find(x => x.AudioQuality == YouTubeQuality.QualityLow && !x.HasVideo) ??
streamInfo.Find(x => x.HasAudio && !x.HasVideo)).Uri;
} }
videoSource.Source = streamInfo.First(x => x.VideoQuality == YouTubeQuality.Quality240P).Uri;
break; break;
case "144p": case "144p":
videoSource.Source = streamInfo.First(x => x.VideoQuality == YouTubeQuality.Quality144P).Uri; if (streamInfo.First(x => x.VideoQuality == YouTubeQuality.Quality144P).HasAudio)
try { audioSource.Source = streamInfo.First(x => x.AudioQuality == YouTubeQuality.QualityLow).Uri; } isMuxed = true;
catch else
{ {
try { audioSource.Source = streamInfo.First(x => x.AudioQuality == YouTubeQuality.QualityMedium).Uri; } isMuxed = false;
catch { audioSource.Source = streamInfo.First(x => x.AudioQuality == YouTubeQuality.QualityHigh).Uri; } audioSource.Source = (streamInfo.Find(x => x.AudioQuality == YouTubeQuality.QualityLow && !x.HasVideo) ??
streamInfo.Find(x => x.HasAudio && !x.HasVideo)).Uri;
} }
videoSource.Source = streamInfo.First(x => x.VideoQuality == YouTubeQuality.Quality144P).Uri;
break; break;
} }
needUpdateTimecode = true; needUpdateTimecode = true;
videoSource.Play(); videoSource.Play();
} }
//catch catch
{ {
} }
@@ -481,6 +515,7 @@ namespace FoxTube
if (videoSource.CurrentState == MediaElementState.Playing) if (videoSource.CurrentState == MediaElementState.Playing)
videoSource.Pause(); videoSource.Pause();
else if (videoSource.CurrentState == MediaElementState.Paused) else if (videoSource.CurrentState == MediaElementState.Paused)
if((audioReady && videoReady) || isMuxed)
videoSource.Play(); videoSource.Play();
} }
@@ -489,16 +524,38 @@ namespace FoxTube
switch (audioSource.CurrentState) switch (audioSource.CurrentState)
{ {
case MediaElementState.Buffering: case MediaElementState.Buffering:
if(videoSource.CurrentState != MediaElementState.Buffering)
videoSource.Pause(); videoSource.Pause();
break; break;
case MediaElementState.Playing: case MediaElementState.Playing:
if(videoSource.CurrentState == MediaElementState.Paused) if (videoSource.CurrentState == MediaElementState.Paused)
videoSource.Play(); videoSource.Play();
else if (videoSource.CurrentState == MediaElementState.Buffering)
audioSource.Pause();
break; break;
} }
} }
private void videoSource_Opened(object sender, RoutedEventArgs arg)
{
if(!isMuxed)
{
if(sender == videoSource)
{
videoReady = true;
if (audioReady && ((timecodeBackup == 0 && (bool)settings.Values["videoAutoplay"]) || timecodeBackup > 0))
play_Click(this, null);
}
else if(sender == audioSource)
{
audioReady = true;
if (videoReady && ((timecodeBackup == 0 && (bool)settings.Values["videoAutoplay"]) || timecodeBackup > 0))
play_Click(this, null);
}
}
}
private void videoSource_CurrentStateChanged(object sender, RoutedEventArgs e) private void videoSource_CurrentStateChanged(object sender, RoutedEventArgs e)
{ {
if(videoSource.CurrentState == MediaElementState.Playing && needUpdateTimecode) if(videoSource.CurrentState == MediaElementState.Playing && needUpdateTimecode)
@@ -510,6 +567,7 @@ namespace FoxTube
switch(videoSource.CurrentState) switch(videoSource.CurrentState)
{ {
case MediaElementState.Buffering: case MediaElementState.Buffering:
audioSource.Position = videoSource.Position;
audioSource.Pause(); audioSource.Pause();
bufferingBar.Visibility = Visibility.Visible; bufferingBar.Visibility = Visibility.Visible;
@@ -551,12 +609,6 @@ namespace FoxTube
play.Content = "\xE103"; play.Content = "\xE103";
touchPlay.Content = "\xE103"; touchPlay.Content = "\xE103";
if (Math.Round(videoSource.Position.TotalSeconds, 1) != Math.Round(audioSource.Position.TotalSeconds, 1))
{
Debug.WriteLine($"Correcting tracks synchronization (Video track position: {videoSource.Position}; Audio track position: {audioSource.Position})");
audioSource.Position = videoSource.Position;
}
systemControls.PlaybackStatus = MediaPlaybackStatus.Playing; systemControls.PlaybackStatus = MediaPlaybackStatus.Playing;
break; break;
@@ -796,7 +848,7 @@ namespace FoxTube
case VirtualKey.Left: case VirtualKey.Left:
back10_Click(this, null); back10_Click(this, null);
break; break;
case Windows.System.VirtualKey.Right: case VirtualKey.Right:
fwd30_Click(this, null); fwd30_Click(this, null);
break; break;
} }
@@ -806,5 +858,10 @@ namespace FoxTube
{ {
LoadTrack(); LoadTrack();
} }
private void videoSource_BufferingProgressChanged(object sender, RoutedEventArgs e)
{
bufferingLevel.Value = (audioSource.Source != null && videoSource.BufferingProgress > audioSource.BufferingProgress ? audioSource.BufferingProgress : videoSource.BufferingProgress) * 100;
}
} }
} }