Commit 2cc769e2 authored by Martin Finkel's avatar Martin Finkel Committed by Steve Lhomme

#116 remove setting and add "restart" option when appropriate

parent 60c354a2
using VLC.Model.Video;
using VLC.Utils;
using VLC.ViewModels;
namespace VLC.Commands.VideoLibrary
{
public class RestartAndPlayCommand : AlwaysExecutableCommand
{
public override void Execute(object parameter)
{
if(parameter is VideoItem video)
video.TimeWatchedSeconds = 0;
Locator.VideoLibraryVM.OpenVideo.Execute(parameter);
}
}
}
\ No newline at end of file
......@@ -18,7 +18,7 @@ namespace VLC.Commands.VideoPlayer
{
public override async void Execute(object parameter)
{
await Locator.MediaPlaybackViewModel.UpdatePosition();
Locator.MediaPlaybackViewModel.UpdatePosition();
Locator.MediaPlaybackViewModel.PlaybackService.Stop();
}
......
......@@ -7,12 +7,9 @@
* Refer to COPYING file of the official project for license
**********************************************************************/
using Windows.UI.Core;
using System;
using System.Collections.ObjectModel;
using System.Threading.Tasks;
using SQLite;
using VLC.Commands.MusicPlayer;
using VLC.Model.Music;
using System.Collections.Generic;
using System.Linq;
......@@ -20,14 +17,9 @@ using VLC.Helpers;
using VLC.Model;
using VLC.Model.Video;
using VLC.Utils;
using System.Diagnostics;
using VLC.Services.RunTime;
using VLC.Model.Stream;
using Windows.Storage;
using System.IO;
using libVLCX;
using VLC.ViewModels;
using VLC.Database;
using Windows.Media.Devices;
namespace VLC.Services.RunTime
......@@ -271,28 +263,10 @@ namespace VLC.Services.RunTime
#region Playback methods
private async Task<float> FetchPreviousPosition(IMediaItem media)
float FetchPreviousPosition(IMediaItem media)
{
var video = media as VideoItem;
if (video == null)
if (!(media is VideoItem video))
return 0;
var roamFile = await ApplicationData.Current.RoamingFolder.TryGetItemAsync("roamVideo.txt");
if (roamFile != null)
{
var roamVideos = await FileIO.ReadLinesAsync(roamFile as StorageFile);
if (roamVideos.Any())
{
if (roamVideos[0] == media.Name)
{
int leftTime = 0;
if (int.TryParse(roamVideos[1], out leftTime))
{
video.TimeWatchedSeconds = leftTime;
}
}
}
}
TileHelper.UpdateVideoTile();
// VLC expects a start-time in seconds
......@@ -358,11 +332,9 @@ namespace VLC.Services.RunTime
CurrentMedia.addOption(!Locator.SettingsVM.HardwareAccelerationEnabled ? ":avcodec-hw=none" : ":avcodec-hw=d3d11va");
if (DeviceHelper.GetDeviceType() == DeviceTypeEnum.Phone)
CurrentMedia.addOption(!Locator.SettingsVM.HardwareAccelerationEnabled ? ":avcodec-threads=0" : ":avcodec-threads=1");
if (Locator.SettingsVM.ResumePreviousPosition)
{
var pos = await FetchPreviousPosition(media);
var pos = FetchPreviousPosition(media);
CurrentMedia.addOption($":start-time={pos}");
}
if (_mediaPlayer == null)
......
......@@ -287,7 +287,7 @@ namespace VLC.Utils
public static string NotificationWhenSongStarts => _resourcesLoader.GetString(nameof(NotificationWhenSongStarts));
public static string VideoPlaybackInBackground => _resourcesLoader.GetString(nameof(VideoPlaybackInBackground));
public static string CompactOverlayPiP => _resourcesLoader.GetString(nameof(CompactOverlayPiP));
public static string ResumeOrRestartPlayback => _resourcesLoader.GetString(nameof(ResumeOrRestartPlayback));
public static string Restart => _resourcesLoader.GetString(nameof(Restart));
public static string EvenIfBackground => _resourcesLoader.GetString(nameof(EvenIfBackground));
public static string EvenIfNotBackground => _resourcesLoader.GetString(nameof(EvenIfNotBackground));
public static string NeedRestart => _resourcesLoader.GetString(nameof(NeedRestart));
......
......@@ -72,6 +72,7 @@
<Compile Include="$(MSBuildThisFileDirectory)Commands\VideoLibrary\CloseFlyoutAndPlayVideoCommand.cs" />
<Compile Include="$(MSBuildThisFileDirectory)Commands\VideoLibrary\FavoriteVideoCommand.cs" />
<Compile Include="$(MSBuildThisFileDirectory)Commands\VideoLibrary\PickMediaCommand.cs" />
<Compile Include="$(MSBuildThisFileDirectory)Commands\VideoLibrary\RestartAndPlayCommand.cs" />
<Compile Include="$(MSBuildThisFileDirectory)Commands\VideoLibrary\TVShowClickedCommand.cs" />
<Compile Include="$(MSBuildThisFileDirectory)Commands\VideoPlayer\DownloadSubtitleCommand.cs" />
<Compile Include="$(MSBuildThisFileDirectory)Commands\VideoPlayer\InitPiPCommand.cs" />
......
......@@ -468,26 +468,12 @@ namespace VLC.ViewModels
await Locator.PlaybackService.SetPlaylist(new List<IMediaItem> { video });
}
public async Task UpdatePosition()
public void UpdatePosition()
{
if (Locator.VideoPlayerVm.CurrentVideo != null)
{
Locator.VideoPlayerVm.CurrentVideo.TimeWatchedSeconds = (int)((double)Time / 1000); ;
Locator.VideoPlayerVm.CurrentVideo.TimeWatchedSeconds = (int)((double)Time / 1000);
Locator.MediaLibrary.UpdateVideo(Locator.VideoPlayerVm.CurrentVideo);
try
{
var file = await ApplicationData.Current.RoamingFolder.CreateFileAsync("roamVideo.txt",
CreationCollisionOption.ReplaceExisting);
await FileIO.WriteLinesAsync(file, new[]
{
Locator.VideoPlayerVm.CurrentVideo.Name,
Locator.VideoPlayerVm.CurrentVideo.TimeWatchedSeconds.ToString()
});
}
catch (Exception e)
{
LogHelper.Log(e.Message);
}
}
}
......
......@@ -623,12 +623,6 @@ namespace VLC.ViewModels.Settings
public ChangeSettingsViewCommand ChangeSettingsViewCommand { get; } = new ChangeSettingsViewCommand();
public bool ResumePreviousPosition
{
get => ApplicationSettingsHelper.ReadSettingsValue(nameof(ResumePreviousPosition)) as bool? ?? true;
set => ApplicationSettingsHelper.SaveSettingsValue(nameof(ResumePreviousPosition), value);
}
public static void SwitchLanguage(Languages language)
{
var currentCulture = "en-US";
......
......@@ -100,7 +100,7 @@ namespace VLC.ViewModels.VideoVM
public static TVShowClickedCommand TVShowClickedCommand { get; private set; } = new TVShowClickedCommand();
public PlayVideoCommand OpenVideo { get; private set; } = new PlayVideoCommand();
public RestartAndPlayCommand RestartAndPlayCommand { get; } = new RestartAndPlayCommand();
public CloseFlyoutAndPlayVideoCommand CloseFlyoutAndPlayVideoCommand { get; private set; } = new CloseFlyoutAndPlayVideoCommand();
public DeleteFromLibraryCommand DeleteFromLibraryCommand { get; private set; } = new DeleteFromLibraryCommand();
public ChangeVideoViewCommand ChangeVideoViewCommand { get; private set; } = new ChangeVideoViewCommand();
......
......@@ -1161,9 +1161,9 @@
<source>Czech</source>
<target state="new">Czech</target>
</trans-unit>
<trans-unit id="ResumeOrRestartPlayback" translate="yes" xml:space="preserve">
<source>Resume or restart playback</source>
<target state="new">Resume or restart playback</target>
<trans-unit id="Restart" translate="yes" xml:space="preserve">
<source>restart</source>
<target state="new">restart</target>
</trans-unit>
</group>
</body>
......
......@@ -1161,9 +1161,9 @@
<source>Czech</source>
<target state="new">Czech</target>
</trans-unit>
<trans-unit id="ResumeOrRestartPlayback" translate="yes" xml:space="preserve">
<source>Resume or restart playback</source>
<target state="new">Resume or restart playback</target>
<trans-unit id="Restart" translate="yes" xml:space="preserve">
<source>restart</source>
<target state="new">restart</target>
</trans-unit>
</group>
</body>
......
......@@ -1161,9 +1161,9 @@
<source>Czech</source>
<target state="new">Czech</target>
</trans-unit>
<trans-unit id="ResumeOrRestartPlayback" translate="yes" xml:space="preserve">
<source>Resume or restart playback</source>
<target state="new">Resume or restart playback</target>
<trans-unit id="Restart" translate="yes" xml:space="preserve">
<source>restart</source>
<target state="new">restart</target>
</trans-unit>
</group>
</body>
......
......@@ -1161,9 +1161,9 @@
<source>Czech</source>
<target state="new">Czech</target>
</trans-unit>
<trans-unit id="ResumeOrRestartPlayback" translate="yes" xml:space="preserve">
<source>Resume or restart playback</source>
<target state="new">Resume or restart playback</target>
<trans-unit id="Restart" translate="yes" xml:space="preserve">
<source>restart</source>
<target state="new">restart</target>
</trans-unit>
</group>
</body>
......
......@@ -1161,9 +1161,9 @@
<source>Czech</source>
<target state="new">Czech</target>
</trans-unit>
<trans-unit id="ResumeOrRestartPlayback" translate="yes" xml:space="preserve">
<source>Resume or restart playback</source>
<target state="new">Resume or restart playback</target>
<trans-unit id="Restart" translate="yes" xml:space="preserve">
<source>restart</source>
<target state="new">restart</target>
</trans-unit>
</group>
</body>
......
......@@ -1161,9 +1161,9 @@
<source>Czech</source>
<target state="new">Czech</target>
</trans-unit>
<trans-unit id="ResumeOrRestartPlayback" translate="yes" xml:space="preserve">
<source>Resume or restart playback</source>
<target state="new">Resume or restart playback</target>
<trans-unit id="Restart" translate="yes" xml:space="preserve">
<source>restart</source>
<target state="new">restart</target>
</trans-unit>
</group>
</body>
......
......@@ -1161,9 +1161,9 @@
<source>Czech</source>
<target state="new">Czech</target>
</trans-unit>
<trans-unit id="ResumeOrRestartPlayback" translate="yes" xml:space="preserve">
<source>Resume or restart playback</source>
<target state="new">Resume or restart playback</target>
<trans-unit id="Restart" translate="yes" xml:space="preserve">
<source>restart</source>
<target state="new">restart</target>
</trans-unit>
</group>
</body>
......
......@@ -1161,9 +1161,9 @@
<source>Czech</source>
<target state="new">Czech</target>
</trans-unit>
<trans-unit id="ResumeOrRestartPlayback" translate="yes" xml:space="preserve">
<source>Resume or restart playback</source>
<target state="new">Resume or restart playback</target>
<trans-unit id="Restart" translate="yes" xml:space="preserve">
<source>restart</source>
<target state="new">restart</target>
</trans-unit>
</group>
</body>
......
......@@ -1161,9 +1161,9 @@
<source>Czech</source>
<target state="new">Czech</target>
</trans-unit>
<trans-unit id="ResumeOrRestartPlayback" translate="yes" xml:space="preserve">
<source>Resume or restart playback</source>
<target state="new">Resume or restart playback</target>
<trans-unit id="Restart" translate="yes" xml:space="preserve">
<source>restart</source>
<target state="new">restart</target>
</trans-unit>
</group>
</body>
......
......@@ -1161,9 +1161,9 @@
<source>Czech</source>
<target state="new">Czech</target>
</trans-unit>
<trans-unit id="ResumeOrRestartPlayback" translate="yes" xml:space="preserve">
<source>Resume or restart playback</source>
<target state="new">Resume or restart playback</target>
<trans-unit id="Restart" translate="yes" xml:space="preserve">
<source>restart</source>
<target state="new">restart</target>
</trans-unit>
</group>
</body>
......
......@@ -1161,9 +1161,9 @@
<source>Czech</source>
<target state="new">Czech</target>
</trans-unit>
<trans-unit id="ResumeOrRestartPlayback" translate="yes" xml:space="preserve">
<source>Resume or restart playback</source>
<target state="new">Resume or restart playback</target>
<trans-unit id="Restart" translate="yes" xml:space="preserve">
<source>restart</source>
<target state="new">restart</target>
</trans-unit>
</group>
</body>
......
......@@ -1161,9 +1161,9 @@
<source>Czech</source>
<target state="new">Czech</target>
</trans-unit>
<trans-unit id="ResumeOrRestartPlayback" translate="yes" xml:space="preserve">
<source>Resume or restart playback</source>
<target state="new">Resume or restart playback</target>
<trans-unit id="Restart" translate="yes" xml:space="preserve">
<source>restart</source>
<target state="new">restart</target>
</trans-unit>
</group>
</body>
......
......@@ -1161,9 +1161,9 @@
<source>Czech</source>
<target state="new">Czech</target>
</trans-unit>
<trans-unit id="ResumeOrRestartPlayback" translate="yes" xml:space="preserve">
<source>Resume or restart playback</source>
<target state="new">Resume or restart playback</target>
<trans-unit id="Restart" translate="yes" xml:space="preserve">
<source>restart</source>
<target state="new">restart</target>
</trans-unit>
</group>
</body>
......
......@@ -1161,9 +1161,9 @@
<source>Czech</source>
<target state="new">Czech</target>
</trans-unit>
<trans-unit id="ResumeOrRestartPlayback" translate="yes" xml:space="preserve">
<source>Resume or restart playback</source>
<target state="new">Resume or restart playback</target>
<trans-unit id="Restart" translate="yes" xml:space="preserve">
<source>restart</source>
<target state="new">restart</target>
</trans-unit>
</group>
</body>
......
......@@ -1161,9 +1161,9 @@
<source>Czech</source>
<target state="new">Czech</target>
</trans-unit>
<trans-unit id="ResumeOrRestartPlayback" translate="yes" xml:space="preserve">
<source>Resume or restart playback</source>
<target state="new">Resume or restart playback</target>
<trans-unit id="Restart" translate="yes" xml:space="preserve">
<source>restart</source>
<target state="new">restart</target>
</trans-unit>
</group>
</body>
......
......@@ -1161,9 +1161,9 @@
<source>Czech</source>
<target state="new">Czech</target>
</trans-unit>
<trans-unit id="ResumeOrRestartPlayback" translate="yes" xml:space="preserve">
<source>Resume or restart playback</source>
<target state="new">Resume or restart playback</target>
<trans-unit id="Restart" translate="yes" xml:space="preserve">
<source>restart</source>
<target state="new">restart</target>
</trans-unit>
</group>
</body>
......
......@@ -1161,9 +1161,9 @@
<source>Czech</source>
<target state="new">Czech</target>
</trans-unit>
<trans-unit id="ResumeOrRestartPlayback" translate="yes" xml:space="preserve">
<source>Resume or restart playback</source>
<target state="new">Resume or restart playback</target>
<trans-unit id="Restart" translate="yes" xml:space="preserve">
<source>restart</source>
<target state="new">restart</target>
</trans-unit>
</group>
</body>
......
......@@ -1161,9 +1161,9 @@
<source>Czech</source>
<target state="new">Czech</target>
</trans-unit>
<trans-unit id="ResumeOrRestartPlayback" translate="yes" xml:space="preserve">
<source>Resume or restart playback</source>
<target state="new">Resume or restart playback</target>
<trans-unit id="Restart" translate="yes" xml:space="preserve">
<source>restart</source>
<target state="new">restart</target>
</trans-unit>
</group>
</body>
......
......@@ -13,6 +13,7 @@
<Thickness x:Key="FrameMarginHorizontal">16,0</Thickness>
<Thickness x:Key="FrameMarginTop">0,16,0,0</Thickness>
<Thickness x:Key="FrameMarginBottom">0,0,0,16</Thickness>
<Thickness x:Key="FrameMarginBottomLeft">16,0,0,16</Thickness>
<Thickness x:Key="FrameMarginLeft">16,0,0,0</Thickness>
<Thickness x:Key="FrameMarginRight">0,0,16,0</Thickness>
<x:Double x:Key="FrameMarginSides">16</x:Double>
......
......@@ -762,7 +762,6 @@
<data name="PolishLanguage" xml:space="preserve">
<value>Polish</value>
</data>
<data name="DanishLanguage" xml:space="preserve">
<value>Danish</value>
</data>
......@@ -811,9 +810,6 @@
<data name="CompactOverlayPiP" xml:space="preserve">
<value>use windows 10 pip</value>
</data>
<data name="ResumeOrRestartPlayback" xml:space="preserve">
<value>Resume or restart playback</value>
</data>
<data name="TvUnsafeArea" xml:space="preserve">
<value>TV unsafe area</value>
</data>
......@@ -826,4 +822,7 @@
<data name="NoExtraMargin" xml:space="preserve">
<value>No extra margin</value>
</data>
<data name="Restart" xml:space="preserve">
<value>restart</value>
</data>
</root>
\ No newline at end of file
......@@ -264,13 +264,6 @@
Name="compactOverlayToggle"
Header="{Binding Source={StaticResource Strings}, Path=CompactOverlayPiP}"
IsOn="{Binding CompactOverlayPiP, Mode=TwoWay}" />
<ToggleSwitch Name="ResumeOrRestartPlayback"
Header="{Binding Source={StaticResource Strings}, Path=ResumeOrRestartPlayback}"
OffContent="Restart"
OnContent="Resume"
IsOn="{Binding ResumePreviousPosition, Mode=TwoWay}"/>
<toolkitControls:HeaderedTextBlock Margin="{StaticResource FrameMarginTop}"
Header="{Binding Source={StaticResource Strings}, Path=SubtitlesEncoding}"
Text="{Binding Source={StaticResource Strings}, Path=NeedRestart}"
......
......@@ -74,6 +74,7 @@
FontFamily="{StaticResource VLCFont}" />
</AppBarButton.Icon>
</AppBarButton>
<AppBarButton Label="{Binding Source={StaticResource Strings}, Path=DeleteSelected}"
Command="{Binding Source={StaticResource Locator}, Path=VideoLibraryVM.DeleteFromLibraryCommand}"
CommandParameter="{Binding}"
......@@ -87,7 +88,21 @@
</AppBarButton.Icon>
</AppBarButton>
</Grid>
<TextBlock Grid.Row="2"
<AppBarButton Grid.Row="2"
Name="RestartPlayback"
Label="{Binding Source={StaticResource Strings}, Path=Restart}"
Click="ActionButton_Click"
Margin="{StaticResource FrameMarginBottomLeft}"
Command="{Binding Source={StaticResource Locator}, Path=VideoLibraryVM.RestartAndPlayCommand}"
CommandParameter="{Binding}"
Visibility="{Binding TimeWatchedSeconds, Converter={StaticResource NegatedCountToVisibilityConverter}}"
Style="{StaticResource AppBarButtonStyleHorizontal}">
<AppBarButton.Icon>
<FontIcon Glyph="&#xE777;"
FontFamily="Segoe MDL2 Assets" />
</AppBarButton.Icon>
</AppBarButton>
<TextBlock Grid.Row="3"
Margin="{StaticResource FrameMarginLeft}"
Style="{StaticResource BodyTextBlockStyle}">
<Run Text="{Binding Type}" />
......@@ -96,7 +111,7 @@
<Run Text="x" />
<Run Text="{Binding Height}" />
</TextBlock>
<TextBlock Grid.Row="3"
<TextBlock Grid.Row="4"
Text="{Binding Path}"
MaxLines="2"
Margin="{StaticResource FrameMarginBothSides}"
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment