Skip to content

Commit

Permalink
v1.2.2.27
Browse files Browse the repository at this point in the history
  • Loading branch information
zdy1988 committed Feb 27, 2023
1 parent f5b65ca commit 2b8269c
Show file tree
Hide file tree
Showing 10 changed files with 471 additions and 164 deletions.
3 changes: 3 additions & 0 deletions src/.changelog
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
v1.2.2.27
1.������Ƶ���Ź��ܣ���֧��MP4��AVI��WMV��ЩWindowsԭ��֧�ֵĸ�ʽ

v1.2.2.26
1.�������洰�ڵ�һϵ�й���

Expand Down
29 changes: 29 additions & 0 deletions src/Converters/VideoDurationToStringConverter.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
using System;
using System.Collections.Generic;
using System.Globalization;
using System.Text;
using System.Windows.Data;
using Zhai.Famil.Converters;

namespace Zhai.PictureView.Converters
{
internal class VideoDurationToStringConverter : ConverterMarkupExtensionBase<VideoDurationToStringConverter>, IValueConverter
{
public object Convert(object value, Type targetType, object parameter, CultureInfo culture)
{
if (value != null)
{
var seconds = (double)value;

return TimeSpan.FromSeconds(seconds).ToString(@"hh\:mm\:ss");
}

return null;
}

public object ConvertBack(object value, Type targetType, object parameter, CultureInfo culture)
{
throw new NotImplementedException();
}
}
}
1 change: 1 addition & 0 deletions src/ImageDecoder.cs
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,7 @@ internal static BitmapSource GetThumb(string filename)
return (Path.GetExtension(filename).ToUpperInvariant()) switch
{
".JPG" or ".JPEG" or ".JPE" or ".PNG" or ".BMP" or ".GIF" or ".ICO" or ".JFIF" => GetWindowsThumbnail(filename),
".MP4" or ".AVI" or ".WMV" => GetWindowsThumbnail(filename),
_ => GetMagickThumbnail(filename),
};
}
Expand Down
370 changes: 222 additions & 148 deletions src/MainWindow.xaml

Large diffs are not rendered by default.

175 changes: 161 additions & 14 deletions src/MainWindow.xaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,9 @@
using System.Threading;
using System.Threading.Tasks;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Input;
using System.Windows.Controls;
using System.Windows.Controls.Primitives;
using Zhai.Famil.Controls;
using Timer = System.Timers.Timer;
using MessageBox = Zhai.Famil.Dialogs.MessageBox;
Expand Down Expand Up @@ -66,22 +67,36 @@ private async void MainWindow_Loaded(object sender, RoutedEventArgs e)

private async void ViewModel_CurrentPictureChanged(object sender, Picture picture)
{
var stream = XamlAnimatedGif.AnimationBehavior.GetSourceStream(Picture);

if (stream != null)
void CleanGif()
{
XamlAnimatedGif.AnimationBehavior.SetSourceUri(Picture, null);
var stream = XamlAnimatedGif.AnimationBehavior.GetSourceStream(Picture);

if (stream != null)
{
XamlAnimatedGif.AnimationBehavior.SetSourceUri(Picture, null);
}
}

CleanGif();

if (picture != null)
{
await InitPicture(picture);
StopVideo();

PictureList.ScrollIntoView(picture);

if (picture.IsAnimation)
if (picture.IsVideo)
{
XamlAnimatedGif.AnimationBehavior.SetSourceUri(Picture, new Uri(picture.PicturePath));
InitVideo(picture);
}
else
{
await InitPicture(picture);

PictureList.ScrollIntoView(picture);

if (picture.IsAnimation)
{
XamlAnimatedGif.AnimationBehavior.SetSourceUri(Picture, new Uri(picture.PicturePath));
}
}
}
}
Expand All @@ -91,8 +106,7 @@ private void ViewModel_CurrentFolderChanged(object sender, DirectoryInfo e)
FolderList.ScrollIntoView(e);
}



#region Picture View
private double PictureOffsetX => Canvas.GetLeft(Picture);
private double PictureOffsetY => Canvas.GetTop(Picture);
private double MoveRectOffsetX => Canvas.GetLeft(MoveRect);
Expand All @@ -101,7 +115,7 @@ private void ViewModel_CurrentFolderChanged(object sender, DirectoryInfo e)
private double AdjustScale => Picture.Width / ViewModel.CurrentPicture.PixelWidth;


private List<Picture> activedPictures = new();
private readonly List<Picture> activedPictures = new();

private void ManagePictureCache(Picture current)
{
Expand Down Expand Up @@ -492,8 +506,9 @@ private void MoveRect_MouseMove(object sender, MouseEventArgs e)
}
}

#endregion

#region Contorllers
#region Picture Contorllers

private async void OpenButton_Click(object sender, RoutedEventArgs e)
{
Expand Down Expand Up @@ -758,6 +773,138 @@ private void MainWindow_PreviewKeyDown(object sender, KeyEventArgs e)

#endregion

#region Video View

private void InitVideo(Picture picture)
{
ViewModel.IsVideoErrored = false;
ViewModel.VideoErrorMessage = string.Empty;

this.MediaElement.Source = new Uri(picture.PicturePath);

this.MediaElement.MediaOpened += MediaElement_MediaOpened;

this.MediaElement.MediaEnded += MediaElement_MediaEnded;

this.MediaElement.MediaFailed += MediaElement_MediaFailed;

PlayVideo();
}

private Timer videoTimer;

private void PlayVideo()
{
this.MediaElement.Play();

ViewModel.IsVideoPlaying = true;

if (videoTimer == null)
{
videoTimer = new Timer
{
Interval = 1000
};

videoTimer.Elapsed += VideoTimer_Elapsed;
}

videoTimer.Start();
}

private void PauseVideo()
{
this.MediaElement.Pause();

ViewModel.IsVideoPlaying = false;

videoTimer?.Stop();
}

private void StopVideo()
{
this.MediaElement.Stop();

ViewModel.IsVideoPlaying = false;

videoTimer?.Stop();
}

private void VideoTimer_Elapsed(object sender, System.Timers.ElapsedEventArgs e)
{
this.Dispatcher.Invoke(() =>
{
this.PositionSlider.Value = this.MediaElement.Position.TotalSeconds;
});
}

private void MediaElement_MediaOpened(object sender, RoutedEventArgs e)
{
this.PositionSlider.Maximum = this.MediaElement.NaturalDuration.TimeSpan.TotalSeconds;

ViewModel.CurrentPicture.PixelWidth = this.MediaElement.NaturalVideoWidth;
ViewModel.CurrentPicture.PixelHeight = this.MediaElement.NaturalVideoHeight;
}

private void MediaElement_MediaEnded(object sender, RoutedEventArgs e)
{
StopVideo();
}

private void MediaElement_MediaFailed(object sender, ExceptionRoutedEventArgs e)
{
ViewModel.IsVideoErrored = true;
ViewModel.VideoErrorMessage = e.ErrorException.Message;

StopVideo();
}

#endregion

#region Video Contorllers

private void MediaPlayButton_Click(object sender, RoutedEventArgs e)
{
if (this.MediaElement.HasVideo)
{
PlayVideo();
}
}

private void MediaPauseButton_Click(object sender, RoutedEventArgs e)
{
if (this.MediaElement.HasVideo)
{
PauseVideo();
}
}

private void RotateLeftButton2_Click(object sender, RoutedEventArgs e)
{
if (ViewModel.CurrentPicture == null) return;

ViewModel.RotateAngle += 90;
}

private void RotateRightButton2_Click(object sender, RoutedEventArgs e)
{
if (ViewModel.CurrentPicture == null) return;

ViewModel.RotateAngle -= 90;
}

private void PositionSlider_DragCompleted(object sender, DragCompletedEventArgs e)
{
this.MediaElement.Position = new TimeSpan(0, 0, 0, (int)this.PositionSlider.Value);
}

private void PositionSlider_PreviewMouseUp(object sender, MouseButtonEventArgs e)
{
this.MediaElement.Position = new TimeSpan(0, 0, 0, (int)this.PositionSlider.Value);
}

#endregion

private void AboutButton_Click(object sender, RoutedEventArgs e)
{
var window = new AboutWindow
Expand Down
10 changes: 10 additions & 0 deletions src/Picture.cs
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,16 @@ public bool IsAnimation
}
}

public bool IsVideo
{
get
{
if (string.IsNullOrEmpty(PicturePath)) return false;

return PictureSupport.IsVideo(PicturePath);
}
}

public bool IsLoaded
{
get
Expand Down
8 changes: 7 additions & 1 deletion src/PictureSupport.cs
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,11 @@ internal static class PictureSupport
".pgm", ".ppm", ".cut", ".exr", ".dib", ".emf", ".wmf", ".wpg", ".pcx", ".xbm", ".xpm",
};

internal static string[] All { get; } = (new List<IEnumerable<string>> { JPEG, PortableNetworkGraphic, GraphicsInterchangeFormat, Icon, Photoshop, Vector, Camera, Others }).Aggregate((x, y) => x.Concat(y)).ToArray();
internal static string[] Video { get; } = new string[] {
".mp4", ".wmv", ".avi",
};

internal static string[] All { get; } = (new List<IEnumerable<string>> { JPEG, PortableNetworkGraphic, GraphicsInterchangeFormat, Icon, Photoshop, Vector, Camera, Others, Video }).Aggregate((x, y) => x.Concat(y)).ToArray();

internal static string ToFilter(this IEnumerable<string> strings)
{
Expand All @@ -64,6 +68,8 @@ Graphics Interchange Format ({GraphicsInterchangeFormat.ToFilter()})|{GraphicsIn
Others ({Others.ToFilter()})|{Others.ToFilter()}|
All Files (*.*)|*.*";

internal static bool IsVideo(string filename) => Video.Contains(Path.GetExtension(filename).ToLower());

internal static bool IsSupported(string filename) => All.Contains(Path.GetExtension(filename).ToLower());

internal static readonly Func<FileInfo, bool> PictureSupportExpression = file => (file.Attributes & (FileAttributes.Hidden | FileAttributes.System | FileAttributes.Temporary)) == 0 && PictureSupport.IsSupported(file.FullName);
Expand Down
33 changes: 33 additions & 0 deletions src/PictureWindowVideoView.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using Zhai.Famil.Common.Mvvm;

namespace Zhai.PictureView
{
internal partial class PictureWindowViewModel : ViewModelBase
{
private bool isVideoPlaying;
public bool IsVideoPlaying
{
get => isVideoPlaying;
set => Set(() => IsVideoPlaying, ref isVideoPlaying, value);
}

private bool isVideoErrored;
public bool IsVideoErrored
{
get => isVideoErrored;
set => Set(() => IsVideoErrored, ref isVideoErrored, value);
}

private string videoErrorMessage;
public string VideoErrorMessage
{
get => videoErrorMessage;
set => Set(() => VideoErrorMessage, ref videoErrorMessage, value);
}
}
}
4 changes: 4 additions & 0 deletions src/PictureWindowViewModel.cs
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,8 @@ public Picture CurrentPicture
//{
// ThreadPool.QueueUserWorkItem(_ => value.DrawThumb());
//}

base.RaisePropertyChanged(nameof(IsCurrentPictureIsVideo));
}
}
}
Expand Down Expand Up @@ -194,6 +196,8 @@ public PictureEffect CurrentPictureEffect

public bool IsCanPicturesNavigated => CurrentPicture != null && Folder != null && (Folder.Count > 1 || Folder.Borthers.Count > 1);

public bool IsCurrentPictureIsVideo => CurrentPicture != null && CurrentPicture.IsVideo;

public ObservableCollection<PictureEffect> Effects { get; }


Expand Down
2 changes: 1 addition & 1 deletion src/Zhai.PictureView.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@

<PropertyGroup>
<Title>ZHAI PICTURE VIEW</Title>
<Version>1.2.2.26</Version>
<Version>1.2.2.27</Version>
<Authors>ZDY</Authors>
<Copyright>Copyright © 2022 ZDY 保留所有权利。</Copyright>
<Description>诞生于我(ZDY)的个人兴趣,我会在有限的时间里维护这个软件。如果在使用的过程中发现什么BUG,欢迎发送描述信息和图片到我的邮箱,也可以在我的GitHub上留言,我会尽力改进软件...</Description>
Expand Down

0 comments on commit 2b8269c

Please sign in to comment.