pause,vol and catagory items work and reading from json

This commit is contained in:
Elias Quinn
2025-06-13 14:18:05 +01:00
parent afe5d2f5ff
commit 9534ed3a8a
41 changed files with 467 additions and 167 deletions

View File

@@ -56,16 +56,16 @@
Grid.Column="0"
Background="#222"
VerticalAlignment="Stretch">
<Button Content="Home" Height="60" Foreground="White" Background="Transparent" Click="Close_Player"/>
<Button Content="Musik" Height="60" Foreground="White" Background="Transparent" Click="Close_Player"/>
<Button Content="Photos" Height="60" Foreground="White" Background="Transparent" Click="Close_Player"/>
<Button Content="Video" Height="60" Foreground="White" Background="Transparent" Click="Close_Player" />
<Button Content="Home" Height="60" Foreground="White" Background="Transparent" Click="Home_OnClick" />
<Button Content="Musik" Height="60" Foreground="White" Background="Transparent" Click="Musik_OnClick"/>
<Button Content="Photos" Height="60" Foreground="White" Background="Transparent" Click="Photo_OnClick"/>
<Button Content="Video" Height="60" Foreground="White" Background="Transparent" Click="Video_OnClick" />
</StackPanel>
<!-- MAIN CONTENT WRAPPED IN A GRID FOR LAYERING -->
<Grid Grid.Column="1" Grid.Row="1">
<!-- ScrollViewer (Background) -->
<ScrollViewer x:Name="ScrollContent" Background="#444" Panel.ZIndex="0">
<ScrollViewer x:Name="ScrollContentHome" Background="#444" Panel.ZIndex="0">
<StackPanel Margin="10">
<!-- Favorites -->
<TextBlock Text="Favorites" FontSize="18" Foreground="White" Margin="0,10"/>
@@ -119,6 +119,27 @@
Panel.ZIndex="1"
Visibility="Collapsed"
Background="Black" />
<!--Catagory-->
<ScrollViewer x:Name="ScrollContentCat" Background="#444" Panel.ZIndex="0" Visibility="Collapsed">
<StackPanel Margin="10">
<!-- Cat-name -->
<TextBlock Name="Name_of_Catagory_Text" Text="Name_of_Catagory" FontSize="18" Foreground="White" Margin="0,10"/>
<WrapPanel Name="Name_of_Catagory">
<Rectangle Fill="LightBlue" Width="150" Height="100" Margin="5"/>
<Rectangle Fill="LightBlue" Width="150" Height="100" Margin="5"/>
<Rectangle Fill="LightBlue" Width="150" Height="100" Margin="5"/>
<Rectangle Fill="LightBlue" Width="150" Height="100" Margin="5"/>
</WrapPanel>
<TextBlock Name="Name_of_Catagory_Text1" Text="Name_of_Catagory1" FontSize="18" Foreground="White" Margin="0,10"/>
<WrapPanel Name="Name_of_Catagory1" Visibility="Collapsed">
<Rectangle Fill="LightBlue" Width="150" Height="100" Margin="5"/>
<Rectangle Fill="LightBlue" Width="150" Height="100" Margin="5"/>
<Rectangle Fill="LightBlue" Width="150" Height="100" Margin="5"/>
<Rectangle Fill="LightBlue" Width="150" Height="100" Margin="5"/>
</WrapPanel>
</StackPanel>
</ScrollViewer>
</Grid>
<!-- SETTINGS BUTTON -->
@@ -134,11 +155,11 @@
VerticalAlignment="Center"
Background="#222">
<TextBlock Text="Titel" Foreground="White" FontSize="16" Margin="10"/>
<Button Content="⏮" Width="40" Margin="10"/>
<Button Content="▶" Width="40" Margin="10"/>
<Button Content="⏭" Width="40" Margin="10"/>
<Button Content="⏮" Width="40" Margin="10" Click="OnItemPriorButtonClick"/>
<Button Content="▶" Width="40" Margin="10" Click="OnItemPauseBtn_Click"/>
<Button Content="⏭" Width="40" Margin="10" Click="OnItemNextButtonClick"/>
<TextBlock Text="🔊" Foreground="White" VerticalAlignment="Center" Margin="10,0"/>
<Slider Width="100" Minimum="0" Maximum="100" Value="50" Margin="10"/>
<Slider Width="100" Minimum="0" Maximum="100" Value="50" Margin="10" ValueChanged="RangeBase_OnValueChanged"/>
</StackPanel>
</Grid>
</Window>

View File

@@ -42,6 +42,8 @@ public partial class MainWindow : Window
LogWindow logWin = new LogWindow(loghelper.GetEntries());
LogHelper log = new LogHelper();
Favorites favorites = new Favorites();
private Catagory Muvie = new Catagory("Muvie");
private Catagory Serie = new Catagory("Serie");
private Catagory Music = new Catagory("Music");
@@ -72,7 +74,6 @@ public partial class MainWindow : Window
public MainWindow()
{
#region Init wpf
InitializeComponent();
//Initialise but Hide
logWin.Hide();
@@ -161,32 +162,74 @@ public partial class MainWindow : Window
#endregion
#region Click Methods
//video player variables
private string path;
private string _category;
private void OnItemPlayButtonClick(object sender, RoutedEventArgs e)
{
if (sender is Button btn && btn.Tag is string filePath)
{
if (filePath.EndsWith(".jpg") || filePath.EndsWith(".png"))
string[] parts = filePath.Split('/');
if (parts.Length == 2)
{
ShowImageWithVLC(filePath); // you'd implement this
}
else
{
PlayVideo(filePath);
string left = parts[0]; // "first"
PlayVideo(left);
path = left;
_category = parts[1];
}
}
}
private void OnItemNextButtonClick(object sender, RoutedEventArgs e)
{
switch (_category.ToLower())
{
case "muvie":
videoArrows(ref Muvie,true); break;
case "serie":
videoArrows(ref Serie,true);break;
case "music":
videoArrows(ref Music,true); break;
case "photos":
videoArrows(ref Photo,true); break;
default:
break;
}
}
private void OnItemPriorButtonClick(object sender, RoutedEventArgs e)
{
switch (_category)
{
case "Muvie":
videoArrows(ref Muvie,false); break;
case "Serie":
videoArrows(ref Serie,false);break;
case "Music":
videoArrows(ref Music,false); break;
case "Photos":
videoArrows(ref Photo,false); break;
default:
break;
}
}
private void OnItemPauseBtn_Click(object sender, RoutedEventArgs e)
{
if (_mediaPlayer.IsPlaying)
{
_mediaPlayer.Pause(); // Pauses the video
}
else
{
_mediaPlayer.SetPause(false); // Unpauses the video
}
}
private void Close_Player(object sender, RoutedEventArgs e)
{
_mediaPlayer.Stop();
VideoView.Visibility = Visibility.Collapsed;
}
void Video_Click(object sender, RoutedEventArgs e)
{
PlayVideo(@"F:\Rio.mp4");
}
private async void scanButton_Click(object sender, RoutedEventArgs e)
{
try
@@ -318,6 +361,41 @@ public partial class MainWindow : Window
}
}
#region Catagory btns
private void Home_OnClick(object sender, RoutedEventArgs e)
{
Close_Player();
ScrollContentCat.Visibility = Visibility.Collapsed;
ScrollContentHome.Visibility = Visibility.Visible;
MenueItems();
}
private void Musik_OnClick(object sender, RoutedEventArgs e)
{
Close_Player();
ScrollContentHome.Visibility = Visibility.Collapsed;
ScrollContentCat.Visibility = Visibility.Visible;
Name_of_Catagory1.Visibility = Visibility.Collapsed;
MenueItems(ref Music);
}
private void Photo_OnClick(object sender, RoutedEventArgs e)
{
Close_Player();
ScrollContentHome.Visibility = Visibility.Collapsed;
ScrollContentCat.Visibility = Visibility.Visible;
Name_of_Catagory1.Visibility = Visibility.Collapsed;
MenueItems(ref Photo);
}
private void Video_OnClick(object sender, RoutedEventArgs e)
{
Close_Player();
ScrollContentHome.Visibility = Visibility.Collapsed;
ScrollContentCat.Visibility = Visibility.Visible;
Name_of_Catagory1.Visibility = Visibility.Visible;
MenueItems(ref Muvie,ref Serie);
}
#endregion
#endregion
#region itemCreation
@@ -412,36 +490,72 @@ public partial class MainWindow : Window
#endregion
#region Comunication
public void addFavorit(ref Item item)
{
favorites.SharedRefs.Add(item);
}
public void ReciveErrorLog(string logMessage)
{
log.Error(logMessage);
}
public void PlayVideo(string filePath)
{
if(suportedVidioFiles.Contains(Path.GetExtension(filePath)))
if(suportedVidioFiles.Contains(Path.GetExtension(filePath))||suportedPhotoFiles.Contains(Path.GetExtension(filePath)))
VideoView.Visibility = Visibility.Visible;
var media = new Media(_libVLC, filePath, FromType.FromPath);
_mediaPlayer.Play(media);
}
public void ShowImageWithVLC(string filePath)
public void videoArrows(ref Catagory catagory, bool next)
{
if (File.Exists(filePath))
catagory = catagory as Catagory;
if (catagory == null || catagory.getAllItems() == null)
{
VideoView.Visibility = Visibility.Visible;
var media = new Media(_libVLC, filePath, FromType.FromPath);
_mediaPlayer.Play(media);
MessageBox.Show("Category or items are null");
return;
}
int tmp = catagory.contains(path);
Media media;
if (next && catagory.getAllItems().Count > tmp)
{
media = new Media(_libVLC, catagory.getAllItems()[tmp + 1].getLink(), FromType.FromPath);
}
else
{
if(tmp >1)
media = new Media(_libVLC, catagory.getAllItems()[tmp - 1].getLink(), FromType.FromPath);
else
{
media = new Media(_libVLC, catagory.getAllItems()[tmp].getLink(), FromType.FromPath);
}
}
if(media!=null)
_mediaPlayer.Play(media);
}
private void Close_Player()
{
_mediaPlayer.Stop();
VideoView.Visibility = Visibility.Collapsed;
}
#endregion
#endregion
#region HomeMenue
#region Menue
void MenueItems(ref Catagory catagory)
{
PopulatePanelWithItemsCatagorised(Name_of_Catagory,ref catagory);
}
void MenueItems(ref Catagory catagory,ref Catagory catagory1)
{
PopulatePanelWithItemsCatagorised(Name_of_Catagory,ref catagory);
PopulatePanelWithItemsCatagorised(Name_of_Catagory1,ref catagory1);
}
void MenueItems()
{
PopulatePanelWithItems(Muvie.getAllItems(), Muvies_Home);
@@ -452,78 +566,99 @@ public partial class MainWindow : Window
#endregion
#region PanelPop
private void PopulatePanelWithItemsCatagorised(Panel targetPanel,ref Catagory catagory)
{
if (catagory.name == "Serie")
{
Name_of_Catagory_Text1.Text = catagory.name;
}
else
{
Name_of_Catagory_Text.Text = catagory.name;
}
PopulatePanelWithItems(catagory.getAllItems(),targetPanel);
}
private void PopulatePanelWithItems(List<Item> items, Panel targetPanel)
{
targetPanel.Children.Clear();
foreach (var item in items)
{
var name = item.getName();
var image = item.getImage();
var isFoto = item.getType() == "Photo";
var path = item.getLink();
var buttonText = isFoto ? "Show" : "Play";
if (image == null)
continue; // Skip if image is not available
// Container for stacking label, image, and button
var container = new Grid
{
Width = 150,
Height = 120,
Margin = new Thickness(5)
};
targetPanel.Children.Clear();
byte tmp = 0;
foreach (var item in items)
{
if(tmp >= 10)
break;
if (ScrollContentHome.Visibility == Visibility.Visible)
tmp++;
if (tmp < 10)
{
var name = item.getName();
var image = item.getImage();
var isFoto = item.getType() == "Photo";
var path = item.getLink();
var buttonText = isFoto ? "Show" : "Play";
// Define rows for layout
container.RowDefinitions.Add(new RowDefinition { Height = new GridLength(1, GridUnitType.Star) }); // Image
container.RowDefinitions.Add(new RowDefinition { Height = new GridLength(30) }); // Button
if (image == null)
continue; // Skip if image is not available
// Image
var imgControl = new System.Windows.Controls.Image
{
Source = image,
Width = 150,
Height = 90,
Stretch = Stretch.UniformToFill
};
// Container for stacking label, image, and button
var container = new Grid
{
Width = 150,
Height = 120,
Margin = new Thickness(5)
};
Grid.SetRow(imgControl, 0);
container.Children.Add(imgControl);
// Define rows for layout
container.RowDefinitions.Add(new RowDefinition { Height = new GridLength(1, GridUnitType.Star) }); // Image
container.RowDefinitions.Add(new RowDefinition { Height = new GridLength(30) }); // Button
// Label (overlays top-left, optional)
var label = new Label
{
Content = name,
HorizontalAlignment = HorizontalAlignment.Left,
VerticalAlignment = VerticalAlignment.Top,
Background = new SolidColorBrush(Color.FromArgb(180, 0, 0, 0)),
Foreground = Brushes.White,
Padding = new Thickness(4),
FontSize = 12
};
Grid.SetRow(label, 0);
container.Children.Add(label);
// Image
var imgControl = new System.Windows.Controls.Image
{
Source = image,
Width = 150,
Height = 90,
Stretch = Stretch.UniformToFill
};
// Button
var btn = new Button
{
Content = buttonText,
Height = 25,
Width = 140,
HorizontalAlignment = HorizontalAlignment.Center,
VerticalAlignment = VerticalAlignment.Center,
Margin = new Thickness(0, 0, 0, 5)
};
btn.Click += (s, e) => PlayVideo(path);
Grid.SetRow(btn, 1);
container.Children.Add(btn);
Grid.SetRow(imgControl, 0);
container.Children.Add(imgControl);
// Add to target UI panel
targetPanel.Children.Add(container);
}
}
// Label (overlays top-left, optional)
var label = new Label
{
Content = name,
HorizontalAlignment = HorizontalAlignment.Left,
VerticalAlignment = VerticalAlignment.Top,
Background = new SolidColorBrush(Color.FromArgb(180, 0, 0, 0)),
Foreground = Brushes.White,
Padding = new Thickness(4),
FontSize = 12
};
Grid.SetRow(label, 0);
container.Children.Add(label);
// Button
var btn = new Button
{
Content = buttonText,
Height = 25,
Width = 140,
HorizontalAlignment = HorizontalAlignment.Center,
VerticalAlignment = VerticalAlignment.Center,
Margin = new Thickness(0, 0, 0, 5)
};
btn.Click += (s, e) => PlayVideo(path);
Grid.SetRow(btn, 1);
container.Children.Add(btn);
// Add to target UI panel
targetPanel.Children.Add(container);
}
}
}
#endregion
@@ -620,5 +755,20 @@ public partial class MainWindow : Window
#endregion
#region sliders
private void RangeBase_OnValueChanged(object sender, RoutedPropertyChangedEventArgs<double> e)
{
if (sender is Slider&&_mediaPlayer != null)
{
Slider slider = sender as Slider;
int value = Convert.ToInt32(slider.Value);
_mediaPlayer.Volume = value;
log.Log("VolumeChanged");
}
}
#endregion
}