applying new struckture and working vlc
This commit is contained in:
36
ShadowStream/Views/LogIn.xaml
Normal file
36
ShadowStream/Views/LogIn.xaml
Normal file
@@ -0,0 +1,36 @@
|
||||
<Window x:Class="ShadowStream.LogIn"
|
||||
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
|
||||
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
|
||||
Title="Log In" Height="300" Width="400"
|
||||
WindowStartupLocation="CenterScreen"
|
||||
ResizeMode="NoResize">
|
||||
<Grid Margin="20">
|
||||
<Grid.RowDefinitions>
|
||||
<RowDefinition Height="Auto"/>
|
||||
<RowDefinition Height="Auto"/>
|
||||
<RowDefinition Height="Auto"/>
|
||||
<RowDefinition Height="*"/>
|
||||
</Grid.RowDefinitions>
|
||||
|
||||
<TextBlock Text="Please sign in"
|
||||
FontSize="20"
|
||||
FontWeight="Bold"
|
||||
HorizontalAlignment="Center"
|
||||
Margin="0,0,0,20"/>
|
||||
|
||||
<StackPanel Grid.Row="1" Orientation="Vertical" Margin="0,0,0,10">
|
||||
<TextBlock Text="Username" Margin="0,0,0,5"/>
|
||||
<TextBox x:Name="UsernameBox" Width="250" Height="25"/>
|
||||
</StackPanel>
|
||||
|
||||
<StackPanel Grid.Row="2" Orientation="Vertical" Margin="0,0,0,20">
|
||||
<TextBlock Text="Password" Margin="0,0,0,5"/>
|
||||
<PasswordBox x:Name="PasswordBox" Width="250" Height="25"/>
|
||||
</StackPanel>
|
||||
|
||||
<Button Grid.Row="3" Content="Log In"
|
||||
Width="100" Height="30"
|
||||
HorizontalAlignment="Center"
|
||||
Click="LogIn_Click"/>
|
||||
</Grid>
|
||||
</Window>
|
32
ShadowStream/Views/LogIn.xaml.cs
Normal file
32
ShadowStream/Views/LogIn.xaml.cs
Normal file
@@ -0,0 +1,32 @@
|
||||
using System.Windows;
|
||||
using file_finder__test;
|
||||
using file_finder__test.DataBaseModules;
|
||||
|
||||
namespace ShadowStream;
|
||||
|
||||
public partial class LogIn : Window
|
||||
{
|
||||
DataBase dataBase = new DataBase();
|
||||
public LogIn()
|
||||
{
|
||||
InitializeComponent();
|
||||
}
|
||||
private void LogIn_Click(object sender, RoutedEventArgs e)
|
||||
{
|
||||
// VERY simple bypass logic: accept any non-empty credentials
|
||||
if (!string.IsNullOrWhiteSpace(UsernameBox.Text)
|
||||
&& !string.IsNullOrWhiteSpace(PasswordBox.Password))
|
||||
{
|
||||
/*var main = new MainWindow();
|
||||
main.Show();
|
||||
this.Close();*/
|
||||
}
|
||||
else
|
||||
{
|
||||
MessageBox.Show("Please enter username and password.",
|
||||
"Login Failed",
|
||||
MessageBoxButton.OK,
|
||||
MessageBoxImage.Warning);
|
||||
}
|
||||
}
|
||||
}
|
144
ShadowStream/Views/MainWindow.xaml
Normal file
144
ShadowStream/Views/MainWindow.xaml
Normal file
@@ -0,0 +1,144 @@
|
||||
<Window x:Class="ModuleManager.MainWindow"
|
||||
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
|
||||
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
|
||||
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
|
||||
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
|
||||
xmlns:vlc="clr-namespace:LibVLCSharp.WPF;assembly=LibVLCSharp.WPF"
|
||||
mc:Ignorable="d"
|
||||
Title="MainWindow" Height="450" Width="800">
|
||||
<Grid>
|
||||
<!-- Layout Definitions -->
|
||||
<Grid.ColumnDefinitions>
|
||||
<ColumnDefinition Width="200"/>
|
||||
<ColumnDefinition/>
|
||||
</Grid.ColumnDefinitions>
|
||||
<Grid.RowDefinitions>
|
||||
<RowDefinition Height="60"/> <!-- Top bar -->
|
||||
<RowDefinition/> <!-- Content -->
|
||||
<RowDefinition Height="70"/> <!-- Bottom player -->
|
||||
</Grid.RowDefinitions>
|
||||
|
||||
<!-- TOP BAR -->
|
||||
<Grid Grid.ColumnSpan="2" Grid.Row="0" Background="#333">
|
||||
<Button Content="Login"
|
||||
Width="80"
|
||||
Margin="10,10,0,10"
|
||||
HorizontalAlignment="Left"
|
||||
VerticalAlignment="Center"/>
|
||||
|
||||
<Grid HorizontalAlignment="Center" VerticalAlignment="Center" Width="300">
|
||||
<TextBox Name="SearchBox"
|
||||
Padding="8"
|
||||
FontSize="14"
|
||||
Background="White"
|
||||
Foreground="Black"/>
|
||||
<TextBlock Text="Search..."
|
||||
Margin="12,0,0,0"
|
||||
VerticalAlignment="Center"
|
||||
Foreground="Gray"
|
||||
IsHitTestVisible="False"/>
|
||||
</Grid>
|
||||
|
||||
<StackPanel Orientation="Horizontal"
|
||||
HorizontalAlignment="Right"
|
||||
Margin="0,0,20,0"
|
||||
VerticalAlignment="Center">
|
||||
<Button Content="scann"
|
||||
Width="40"
|
||||
Height="40"
|
||||
Margin="0,0,10,0"
|
||||
Click="scanButton_Click"/>
|
||||
</StackPanel>
|
||||
</Grid>
|
||||
|
||||
<!-- LEFT NAVIGATION -->
|
||||
<StackPanel Grid.Row="1"
|
||||
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" />
|
||||
</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">
|
||||
<StackPanel Margin="10">
|
||||
<!-- Favorites -->
|
||||
<TextBlock Text="Favorites" FontSize="18" Foreground="White" Margin="0,10"/>
|
||||
<WrapPanel Name="Favorites_Home">
|
||||
<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>
|
||||
|
||||
<!-- Movies -->
|
||||
<TextBlock Text="Movies" FontSize="18" Foreground="White" Margin="0,20,0,10"/>
|
||||
<WrapPanel Name="Muvies_Home">
|
||||
<Rectangle Fill="LightGreen" Width="150" Height="100" Margin="5"/>
|
||||
<Rectangle Fill="LightGreen" Width="150" Height="100" Margin="5"/>
|
||||
<Rectangle Fill="LightGreen" Width="150" Height="100" Margin="5"/>
|
||||
<Rectangle Fill="LightGreen" Width="150" Height="100" Margin="5"/>
|
||||
</WrapPanel>
|
||||
|
||||
<!-- Series -->
|
||||
<TextBlock Text="Series" FontSize="18" Foreground="White" Margin="0,20,0,10"/>
|
||||
<WrapPanel Name="Series_Home">
|
||||
<Rectangle Fill="LightGreen" Width="150" Height="100" Margin="5"/>
|
||||
<Rectangle Fill="LightGreen" Width="150" Height="100" Margin="5"/>
|
||||
<Rectangle Fill="LightGreen" Width="150" Height="100" Margin="5"/>
|
||||
<Rectangle Fill="LightGreen" Width="150" Height="100" Margin="5"/>
|
||||
</WrapPanel>
|
||||
|
||||
<!-- Music -->
|
||||
<TextBlock Text="Music" FontSize="18" Foreground="White" Margin="0,20,0,10"/>
|
||||
<WrapPanel Name="Music_Home">
|
||||
<Rectangle Fill="LightCoral" Width="150" Height="100" Margin="5"/>
|
||||
<Rectangle Fill="LightCoral" Width="150" Height="100" Margin="5"/>
|
||||
<Rectangle Fill="LightCoral" Width="150" Height="100" Margin="5"/>
|
||||
<Rectangle Fill="LightCoral" Width="150" Height="100" Margin="5"/>
|
||||
</WrapPanel>
|
||||
|
||||
<!-- Photos -->
|
||||
<TextBlock Text="Photos" FontSize="18" Foreground="White" Margin="0,20,0,10"/>
|
||||
<WrapPanel Name="Photos_Home">
|
||||
<Rectangle Fill="DarkRed" Width="150" Height="100" Margin="5"/>
|
||||
<Rectangle Fill="DarkRed" Width="150" Height="100" Margin="5"/>
|
||||
<Rectangle Fill="DarkRed" Width="150" Height="100" Margin="5"/>
|
||||
<Rectangle Fill="DarkRed" Width="150" Height="100" Margin="5"/>
|
||||
</WrapPanel>
|
||||
</StackPanel>
|
||||
</ScrollViewer>
|
||||
|
||||
<!-- Video Player (Foreground) -->
|
||||
<vlc:VideoView x:Name="VideoView"
|
||||
Panel.ZIndex="1"
|
||||
Visibility="Collapsed"
|
||||
Background="Black" />
|
||||
</Grid>
|
||||
|
||||
<!-- SETTINGS BUTTON -->
|
||||
<Button Grid.Column="0" Grid.Row="2"
|
||||
Content="Settings"
|
||||
Margin="10"
|
||||
HorizontalAlignment="Left"/>
|
||||
|
||||
<!-- PLAYER CONTROLS -->
|
||||
<StackPanel Grid.Column="1" Grid.Row="2"
|
||||
Orientation="Horizontal"
|
||||
HorizontalAlignment="Center"
|
||||
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"/>
|
||||
<TextBlock Text="🔊" Foreground="White" VerticalAlignment="Center" Margin="10,0"/>
|
||||
<Slider Width="100" Minimum="0" Maximum="100" Value="50" Margin="10"/>
|
||||
</StackPanel>
|
||||
</Grid>
|
||||
</Window>
|
624
ShadowStream/Views/MainWindow.xaml.cs
Normal file
624
ShadowStream/Views/MainWindow.xaml.cs
Normal file
@@ -0,0 +1,624 @@
|
||||
using System.Drawing;
|
||||
using System.Text;
|
||||
using System.Windows;
|
||||
using System.Windows.Controls;
|
||||
using System.Windows.Data;
|
||||
using System.Windows.Documents;
|
||||
using System.Windows.Input;
|
||||
using System.Windows.Media;
|
||||
using System.Windows.Media.Imaging;
|
||||
using System.Windows.Navigation;
|
||||
using System.Windows.Shapes;
|
||||
using file_finder__test;
|
||||
using ShadowStream;
|
||||
using ShadowStream.LogHelper;
|
||||
using ShadowStream.Obejeckte;
|
||||
using System.IO;
|
||||
using System.Threading;
|
||||
using ShadowStream.ObjecktForJason;
|
||||
using TagLib;
|
||||
using ShadowStream.Modules;
|
||||
using ShadowStream.ObjecktForJason;
|
||||
using LibVLCSharp.Shared;
|
||||
using Brushes = System.Windows.Media.Brushes;
|
||||
using Color = System.Windows.Media.Color;
|
||||
using File = System.IO.File;
|
||||
using Image = System.Drawing.Image;
|
||||
using Path = System.IO.Path;
|
||||
|
||||
|
||||
namespace ModuleManager;
|
||||
|
||||
/// <summary>
|
||||
/// Interaction logic for MainWindow.xaml
|
||||
/// </summary>
|
||||
//Quinn and Reda and Yazan
|
||||
public partial class MainWindow : Window
|
||||
{ //quinn
|
||||
#region no dont cahnge
|
||||
|
||||
//adding base components used threw out the code
|
||||
private static LogHelper loghelper = new LogHelper();
|
||||
LogWindow logWin = new LogWindow(loghelper.GetEntries());
|
||||
LogHelper log = new LogHelper();
|
||||
|
||||
private Catagory Muvie = new Catagory("Muvie");
|
||||
private Catagory Serie = new Catagory("Serie");
|
||||
private Catagory Music = new Catagory("Music");
|
||||
private Catagory Photo = new Catagory("Photos");
|
||||
|
||||
List<string> suportedVidioFiles = new List<string>();
|
||||
List<string> suportedMusicFiles = new List<string>();
|
||||
List<string> suportedPhotoFiles = new List<string>();
|
||||
|
||||
//root directory
|
||||
List<string> dirs = new List<string>();
|
||||
private int option =2;
|
||||
int specificOption = 0;
|
||||
string rootPath = "F:/";
|
||||
|
||||
FileScanner fileScanner;
|
||||
|
||||
#endregion
|
||||
|
||||
//Quinn
|
||||
#region vlc logic
|
||||
|
||||
private LibVLC _libVLC;
|
||||
private LibVLCSharp.Shared.MediaPlayer _mediaPlayer;
|
||||
|
||||
#endregion
|
||||
//code start
|
||||
public MainWindow()
|
||||
{
|
||||
#region Init wpf
|
||||
|
||||
InitializeComponent();
|
||||
//Initialise but Hide
|
||||
logWin.Hide();
|
||||
//this.Hide();
|
||||
|
||||
|
||||
//Begin Login Process
|
||||
var login = new LogIn();
|
||||
login.Show();
|
||||
|
||||
#endregion
|
||||
|
||||
//Quinn Dont change or remuve!!!
|
||||
#region vlc init
|
||||
|
||||
Core.Initialize(); // Important: load native libvlc binaries
|
||||
|
||||
_libVLC = new LibVLC();
|
||||
_mediaPlayer = new LibVLCSharp.Shared.MediaPlayer(_libVLC);
|
||||
|
||||
VideoView.MediaPlayer = _mediaPlayer;
|
||||
|
||||
#endregion
|
||||
|
||||
#region only exdend. no remuving of code
|
||||
|
||||
//adding all extensions... example values added
|
||||
suportedVidioFiles.Add(".mp4");
|
||||
suportedVidioFiles.Add(".mkv");
|
||||
suportedMusicFiles.Add(".wav");
|
||||
suportedMusicFiles.Add(".mp3");
|
||||
suportedPhotoFiles.Add(".jpg");
|
||||
Createscan();
|
||||
//dirs.Add("C:/");
|
||||
|
||||
//execute and wait for task completion
|
||||
var tmp = fileScanner.ScanAllDrivesAsync();
|
||||
|
||||
//load json parallel to finding drives
|
||||
//add code laiter
|
||||
|
||||
tmp.Wait();
|
||||
foreach (var VARIABLE in tmp.Result)
|
||||
{
|
||||
dirs.Add(VARIABLE);
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
LoadSavedData();
|
||||
|
||||
}
|
||||
//Quinn
|
||||
#region dont change
|
||||
//reminder to self. if issue acures. check if anyone changed folder names
|
||||
|
||||
#region ScannLogic
|
||||
|
||||
void Createscan()
|
||||
{
|
||||
//adding all string arrays to one temp array to do the initial scan of the designated drive
|
||||
int count = 0;
|
||||
string[] tmp = new string[suportedMusicFiles.Count + suportedVidioFiles.Count + suportedPhotoFiles.Count];
|
||||
foreach (var suportedVidioFile in suportedVidioFiles)
|
||||
{
|
||||
tmp[count] = suportedVidioFile;
|
||||
count++;
|
||||
}
|
||||
|
||||
foreach (var suportedMusicFile in suportedMusicFiles)
|
||||
{
|
||||
tmp[count] = suportedMusicFile;
|
||||
count++;
|
||||
}
|
||||
|
||||
foreach (var suportedPhotoFile in suportedPhotoFiles)
|
||||
{
|
||||
tmp[count] = suportedPhotoFile;
|
||||
count++;
|
||||
}
|
||||
//initialise the file scanner with all files endings wanted
|
||||
fileScanner = new FileScanner(tmp);
|
||||
}
|
||||
|
||||
|
||||
#endregion
|
||||
|
||||
#region Click Methods
|
||||
|
||||
private void OnItemPlayButtonClick(object sender, RoutedEventArgs e)
|
||||
{
|
||||
if (sender is Button btn && btn.Tag is string filePath)
|
||||
{
|
||||
if (filePath.EndsWith(".jpg") || filePath.EndsWith(".png"))
|
||||
{
|
||||
ShowImageWithVLC(filePath); // you'd implement this
|
||||
}
|
||||
else
|
||||
{
|
||||
PlayVideo(filePath);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
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
|
||||
{
|
||||
Muvie.clear();
|
||||
Serie.clear();
|
||||
Music.clear();
|
||||
Photo.clear();
|
||||
log.Log("Scanning files...");
|
||||
List<string> tmp = new List<string>();
|
||||
switch (option)
|
||||
{
|
||||
case 0:
|
||||
foreach (var VARIABLE in dirs)
|
||||
{
|
||||
foreach (var tmp2 in await fileScanner.ScanDriveParallel(VARIABLE))
|
||||
{
|
||||
tmp.Add(tmp2);
|
||||
}
|
||||
}
|
||||
break;
|
||||
case 1:
|
||||
foreach (var VARIABLE in await fileScanner.ScanDriveParallel(dirs[specificOption]))
|
||||
{
|
||||
tmp.Add(VARIABLE);
|
||||
}
|
||||
break;
|
||||
case 2:
|
||||
foreach (var VARIABLE in await fileScanner.ScanDriveParallel(rootPath))
|
||||
{
|
||||
tmp.Add(VARIABLE);
|
||||
}
|
||||
break;
|
||||
}
|
||||
log.Log($"Total scanned files: {tmp.Count}");
|
||||
|
||||
var classifier = new FileClassifier();
|
||||
var (musicFiles, videoFiles, photoFiles) = await classifier.ClassifyFilesAsync(tmp, suportedMusicFiles, suportedVidioFiles, suportedPhotoFiles);
|
||||
|
||||
var separator = new VideoSeparator();
|
||||
var (series, movies) = await separator.SeparateVideosAsync(videoFiles);
|
||||
|
||||
|
||||
log.Log($"musicFiles count: {musicFiles.Count}");
|
||||
log.Log($"videoFiles count: {videoFiles.Count}");
|
||||
log.Log($"photoFiles count: {photoFiles.Count}");
|
||||
log.Log($"series count: {series.Count}");
|
||||
log.Log($"movies count: {movies.Count}");
|
||||
|
||||
|
||||
videoFiles = null;
|
||||
|
||||
log.Log("files sorted");
|
||||
|
||||
// Prepare JSON lists
|
||||
List<locJason> muviesJS = new List<locJason>();
|
||||
List<locJason> seriesJS = new List<locJason>();
|
||||
List<locJason> photosJS = new List<locJason>();
|
||||
List<locJason> mucicJS = new List<locJason>();
|
||||
|
||||
JasonToString jasonToString = new JasonToString();
|
||||
|
||||
foreach (var VARIABLE in ItemCreater(movies, "Muvie", false))
|
||||
{
|
||||
Muvie.addItem(VARIABLE);
|
||||
muviesJS.Add(new locJason
|
||||
{
|
||||
path = VARIABLE.getLink(),
|
||||
imageData = jasonToString.BitmapToBase64String(BitmapConversions.BitmapImageToBitmap(VARIABLE.getImage())),
|
||||
type = VARIABLE.getType()
|
||||
});
|
||||
}
|
||||
foreach (var VARIABLE in ItemCreater(series, "Serie", false))
|
||||
{
|
||||
Serie.addItem(VARIABLE);
|
||||
seriesJS.Add(new locJason
|
||||
{
|
||||
path = VARIABLE.getLink(),
|
||||
imageData = jasonToString.BitmapToBase64String(BitmapConversions.BitmapImageToBitmap(VARIABLE.getImage())),
|
||||
type = VARIABLE.getType()
|
||||
});
|
||||
}
|
||||
foreach (var VARIABLE in ItemCreater(photoFiles, "Photo", true))
|
||||
{
|
||||
Photo.addItem(VARIABLE);
|
||||
photosJS.Add(new locJason
|
||||
{
|
||||
path = VARIABLE.getLink(),
|
||||
imageData = jasonToString.BitmapToBase64String(BitmapConversions.BitmapImageToBitmap(VARIABLE.getImage())),
|
||||
type = VARIABLE.getType()
|
||||
});
|
||||
}
|
||||
foreach (var VARIABLE in ItemCreater(musicFiles, "Music", false, true))
|
||||
{
|
||||
Music.addItem(VARIABLE);
|
||||
mucicJS.Add(new locJason
|
||||
{
|
||||
path = VARIABLE.getLink(),
|
||||
imageData = jasonToString.BitmapToBase64String(BitmapConversions.BitmapImageToBitmap(VARIABLE.getImage())),
|
||||
type = VARIABLE.getType()
|
||||
});
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
log.Log("scan finished");
|
||||
|
||||
Jason_Writer jason_Writer = new Jason_Writer();
|
||||
List<Task> tasks = new List<Task>
|
||||
{
|
||||
jason_Writer.SaveList("Muvies", muviesJS),
|
||||
jason_Writer.SaveList("Series", seriesJS),
|
||||
jason_Writer.SaveList("Photos", photosJS),
|
||||
jason_Writer.SaveList("Music", mucicJS)
|
||||
};
|
||||
|
||||
await Task.WhenAll(tasks);
|
||||
mucicJS = null;
|
||||
seriesJS = null;
|
||||
photosJS = null;
|
||||
MenueItems();
|
||||
MessageBox.Show("Scan finished");
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
MessageBox.Show($"An error occurred during scanning:\n\n{ex.ToString()}", "Error", MessageBoxButton.OK, MessageBoxImage.Error);
|
||||
log.Error($"An error occurred during scanning:\n\n{ex.ToString()}");
|
||||
}
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
#region itemCreation
|
||||
|
||||
List<Item> ItemCreater(List<string> path, string type,bool isFoto)
|
||||
{
|
||||
List<Item> items = new List<Item>();
|
||||
|
||||
foreach (var VARIABLE in path)
|
||||
{
|
||||
BitmapImage frame200;
|
||||
if(!isFoto)
|
||||
frame200 = VideoFrameExtractor.GetFrame200(VARIABLE);
|
||||
else
|
||||
{
|
||||
frame200 = new BitmapImage(new Uri(VARIABLE, UriKind.Absolute));
|
||||
}
|
||||
items.Add(new Item(VARIABLE, type,frame200, isFoto,OnItemPlayButtonClick));
|
||||
}
|
||||
|
||||
return items;
|
||||
}
|
||||
|
||||
List<Item> ItemCreater(List<string> paths, string type, bool isFoto, bool Music)
|
||||
{
|
||||
List<Item> items = new List<Item>();
|
||||
|
||||
string baseDir = AppDomain.CurrentDomain.BaseDirectory;
|
||||
string imagePath = Path.Combine(baseDir,"Resources", "Pics", "MusicD.jpeg");
|
||||
|
||||
BitmapImage defaultImage;
|
||||
|
||||
if (File.Exists(imagePath))
|
||||
{
|
||||
defaultImage = new BitmapImage(new Uri(imagePath));
|
||||
defaultImage.Freeze();
|
||||
}
|
||||
else
|
||||
{
|
||||
//this case schould never be called. its to prevent code from breaking because of unautorised muving of musicD!!
|
||||
MessageBox.Show($"Default image not found at: {imagePath}");
|
||||
|
||||
// Create a blank 100x100 transparent BitmapImage fallback
|
||||
int width = 100;
|
||||
int height = 100;
|
||||
int dpi = 96;
|
||||
var pixelFormat = PixelFormats.Pbgra32;
|
||||
int rawStride = (width * pixelFormat.BitsPerPixel + 7) / 8;
|
||||
byte[] rawImage = new byte[rawStride * height]; // all zero = transparent
|
||||
|
||||
var bitmap = BitmapSource.Create(width, height, dpi, dpi, pixelFormat, null, rawImage, rawStride);
|
||||
bitmap.Freeze();
|
||||
|
||||
defaultImage = new BitmapImage();
|
||||
defaultImage = null;
|
||||
}
|
||||
|
||||
foreach (var filePath in paths)
|
||||
{
|
||||
BitmapImage bitmapImage = defaultImage;
|
||||
|
||||
try
|
||||
{
|
||||
var file = TagLib.File.Create(filePath);
|
||||
if (file.Tag.Pictures.Length > 0)
|
||||
{
|
||||
var pic = file.Tag.Pictures[0];
|
||||
using (var ms = new MemoryStream(pic.Data.Data))
|
||||
{
|
||||
var img = new BitmapImage();
|
||||
img.BeginInit();
|
||||
img.CacheOption = BitmapCacheOption.OnLoad;
|
||||
img.StreamSource = ms;
|
||||
img.EndInit();
|
||||
img.Freeze();
|
||||
|
||||
bitmapImage = img;
|
||||
}
|
||||
}
|
||||
}
|
||||
catch
|
||||
{
|
||||
// keep defaultImage if anything fails
|
||||
}
|
||||
|
||||
items.Add(new Item(filePath, type, bitmapImage, isFoto,OnItemPlayButtonClick));
|
||||
}
|
||||
|
||||
return items;
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
#region Comunication
|
||||
public void ReciveErrorLog(string logMessage)
|
||||
{
|
||||
log.Error(logMessage);
|
||||
}
|
||||
public void PlayVideo(string filePath)
|
||||
{
|
||||
if(suportedVidioFiles.Contains(Path.GetExtension(filePath)))
|
||||
VideoView.Visibility = Visibility.Visible;
|
||||
var media = new Media(_libVLC, filePath, FromType.FromPath);
|
||||
_mediaPlayer.Play(media);
|
||||
}
|
||||
|
||||
public void ShowImageWithVLC(string filePath)
|
||||
{
|
||||
if (File.Exists(filePath))
|
||||
{
|
||||
VideoView.Visibility = Visibility.Visible;
|
||||
var media = new Media(_libVLC, filePath, FromType.FromPath);
|
||||
_mediaPlayer.Play(media);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
#endregion
|
||||
|
||||
#endregion
|
||||
|
||||
#region HomeMenue
|
||||
|
||||
void MenueItems()
|
||||
{
|
||||
PopulatePanelWithItems(Muvie.getAllItems(), Muvies_Home);
|
||||
PopulatePanelWithItems(Serie.getAllItems(), Series_Home);
|
||||
PopulatePanelWithItems(Photo.getAllItems(), Photos_Home);
|
||||
PopulatePanelWithItems(Music.getAllItems(), Music_Home);
|
||||
}
|
||||
#endregion
|
||||
|
||||
#region PanelPop
|
||||
|
||||
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)
|
||||
};
|
||||
|
||||
// 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
|
||||
|
||||
// Image
|
||||
var imgControl = new System.Windows.Controls.Image
|
||||
{
|
||||
Source = image,
|
||||
Width = 150,
|
||||
Height = 90,
|
||||
Stretch = Stretch.UniformToFill
|
||||
};
|
||||
|
||||
Grid.SetRow(imgControl, 0);
|
||||
container.Children.Add(imgControl);
|
||||
|
||||
// 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
|
||||
|
||||
#region load saved data
|
||||
|
||||
private async void LoadSavedData()
|
||||
{
|
||||
try
|
||||
{
|
||||
Jason_Writer jason_Writer = new Jason_Writer(); // Use default "Temp Data" folder
|
||||
JasonToString jasonToString = new JasonToString();
|
||||
|
||||
var muvies = await jason_Writer.LoadListAsync("Muvies");
|
||||
var series = await jason_Writer.LoadListAsync("Series");
|
||||
var photos = await jason_Writer.LoadListAsync("Photos");
|
||||
var music = await jason_Writer.LoadListAsync("Music");
|
||||
|
||||
List<Item> MuvieItems = CreateItemsFromJson(muvies);
|
||||
List<Item> SerieItems = CreateItemsFromJson(series);
|
||||
List<Item> PhotoItems = CreateItemsFromJson(photos, isPhoto: true);
|
||||
List<Item> MusicItems = CreateItemsFromJson(music, isPhoto: false, isMusic: true);
|
||||
|
||||
Muvie.addItems(MuvieItems);
|
||||
Serie.addItems(SerieItems);
|
||||
Photo.addItems(PhotoItems);
|
||||
Music.addItems(MusicItems);
|
||||
|
||||
MenueItems(); // Re-populate the UI
|
||||
|
||||
log.Log("Loaded saved data from JSON.");
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
MessageBox.Show($"Failed to load saved data:\n{ex.Message}", "Error", MessageBoxButton.OK, MessageBoxImage.Error);
|
||||
log.Error($"LoadSavedData error: {ex}");
|
||||
}
|
||||
}
|
||||
private List<Item> CreateItemsFromJson(List<locJason> jsonItems)
|
||||
{
|
||||
return CreateItemsFromJson(jsonItems, isPhoto: false, isMusic: false);
|
||||
}
|
||||
|
||||
private List<Item> CreateItemsFromJson(List<locJason> jsonItems, bool isPhoto)
|
||||
{
|
||||
return CreateItemsFromJson(jsonItems, isPhoto, isMusic: false);
|
||||
}
|
||||
|
||||
private List<Item> CreateItemsFromJson(List<locJason> jsonItems, bool isPhoto, bool isMusic)
|
||||
{
|
||||
List<Item> items = new List<Item>();
|
||||
JasonToString jasonToString = new JasonToString();
|
||||
|
||||
foreach (var loc in jsonItems)
|
||||
{
|
||||
BitmapImage bitmapImage = null;
|
||||
|
||||
try
|
||||
{
|
||||
if (!string.IsNullOrEmpty(loc.imageData))
|
||||
{
|
||||
bitmapImage = BitmapConversions.BitmapToBitmapImage(
|
||||
jasonToString.Base64StringToBitmap(loc.imageData)
|
||||
);
|
||||
}
|
||||
else if (isMusic)
|
||||
{
|
||||
string defaultImagePath = Path.Combine(AppDomain.CurrentDomain.BaseDirectory, "Resources", "Pics", "MusicD.jpeg");
|
||||
if (File.Exists(defaultImagePath))
|
||||
{
|
||||
bitmapImage = new BitmapImage(new Uri(defaultImagePath));
|
||||
bitmapImage.Freeze();
|
||||
}
|
||||
}
|
||||
else if (isPhoto && File.Exists(loc.path))
|
||||
{
|
||||
bitmapImage = new BitmapImage(new Uri(loc.path));
|
||||
bitmapImage.Freeze();
|
||||
}
|
||||
}
|
||||
catch
|
||||
{
|
||||
// Handle any corrupt or missing image cases
|
||||
}
|
||||
|
||||
items.Add(new Item(loc.path, loc.type, bitmapImage, isPhoto, OnItemPlayButtonClick));
|
||||
}
|
||||
|
||||
return items;
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
#endregion
|
||||
|
||||
}
|
Reference in New Issue
Block a user