From f9b4fc722ac9d49615e0816f071378de8943625d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jos=C3=A9=20Santos=20Garrido?= Date: Fri, 23 Sep 2022 12:27:34 +0200 Subject: [PATCH 1/4] Fix MediaPlayer constructor --- ConsoleMediaPlayer.Common/MediaPlayer.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/ConsoleMediaPlayer.Common/MediaPlayer.cs b/ConsoleMediaPlayer.Common/MediaPlayer.cs index 0291327..5117330 100644 --- a/ConsoleMediaPlayer.Common/MediaPlayer.cs +++ b/ConsoleMediaPlayer.Common/MediaPlayer.cs @@ -10,7 +10,7 @@ public abstract class MediaPlayer public MediaPlayer(string filePath) { - if (!File.Exists(filePath)) throw new Exception($"El archivo {FilePath} no existe"); + if (!File.Exists(filePath)) throw new Exception($"El archivo {filePath} no existe"); FilePath = filePath; } From 4b6f9d131129276dabad655415151b313b2936db Mon Sep 17 00:00:00 2001 From: Jose Date: Tue, 15 Nov 2022 20:56:22 +0100 Subject: [PATCH 2/4] =?UTF-8?q?Arreglado=20error=20de=20sobrepasar=20la=20?= =?UTF-8?q?altura=20m=C3=A1xima=20de=20la=20consola?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- ConsoleMediaPlayer.Common/ConsoleHelper.cs | 19 +++++++------------ ConsoleMediaPlayer.Common/MediaPlayer.cs | 12 ++++++++---- 2 files changed, 15 insertions(+), 16 deletions(-) diff --git a/ConsoleMediaPlayer.Common/ConsoleHelper.cs b/ConsoleMediaPlayer.Common/ConsoleHelper.cs index d69b41e..4f1777c 100644 --- a/ConsoleMediaPlayer.Common/ConsoleHelper.cs +++ b/ConsoleMediaPlayer.Common/ConsoleHelper.cs @@ -1,9 +1,4 @@ -using System; -using System.Collections.Generic; -using System.Linq; -using System.Runtime.InteropServices; -using System.Text; -using System.Threading.Tasks; +using System.Runtime.InteropServices; namespace ConsoleMediaPlayer.Common { @@ -63,9 +58,9 @@ public static FontInfo[] SetCurrentFont(short fontSize = 0) // Get some settings from current font. if (!SetCurrentConsoleFontEx(ConsoleOutputHandle, false, ref set)) { - var ex = Marshal.GetLastWin32Error(); - Console.WriteLine("Set error " + ex); - throw new System.ComponentModel.Win32Exception(ex); + int error = Marshal.GetLastWin32Error(); + Console.WriteLine("Set error " + error); + throw new System.ComponentModel.Win32Exception(error); } FontInfo after = new FontInfo @@ -78,9 +73,9 @@ public static FontInfo[] SetCurrentFont(short fontSize = 0) } else { - var er = Marshal.GetLastWin32Error(); - Console.WriteLine("Get error " + er); - throw new System.ComponentModel.Win32Exception(er); + int error = Marshal.GetLastWin32Error(); + Console.WriteLine("Get error " + error); + throw new System.ComponentModel.Win32Exception(error); } } } diff --git a/ConsoleMediaPlayer.Common/MediaPlayer.cs b/ConsoleMediaPlayer.Common/MediaPlayer.cs index 5117330..c185f30 100644 --- a/ConsoleMediaPlayer.Common/MediaPlayer.cs +++ b/ConsoleMediaPlayer.Common/MediaPlayer.cs @@ -4,6 +4,7 @@ namespace ConsoleMediaPlayer.Common { public abstract class MediaPlayer { + static readonly Size MARGIN = new Size(1, 2); protected abstract short FontSize { get; } public string FilePath { get; init; } public Size Resolution { get; protected set; } @@ -20,16 +21,19 @@ public MediaPlayer(string filePath) public void ResizeConsoleScreen() { ConsoleHelper.SetCurrentFont(FontSize); - Console.SetWindowSize(Resolution.Width + 1, Resolution.Height + 2); + int width = Resolution.Width + MARGIN.Width; + int height = Resolution.Height + MARGIN.Height; + Console.SetWindowSize(width, height); } protected Size CalculateResolution(Size originalResolution, int desiredHeight) { double aspectRatio = originalResolution.Width / (double)originalResolution.Height; - int width = (int)(desiredHeight * aspectRatio); - int height = desiredHeight / 2; + int maxWindowHeight = Console.LargestWindowHeight - MARGIN.Height; + int height = Math.Min(maxWindowHeight * 2, desiredHeight); + int width = (int)(height * aspectRatio); - return new Size(width, height); + return new Size(width, height / 2); } } From 931559407347fa2d8dc5bc13e2e1e9651eb311d7 Mon Sep 17 00:00:00 2001 From: Jose Date: Tue, 15 Nov 2022 21:35:56 +0100 Subject: [PATCH 3/4] =?UTF-8?q?Arreglo=20error=20de=20calcular=20la=20reso?= =?UTF-8?q?luci=C3=B3n=20antes=20de=20fijar=20el=20tama=C3=B1o=20de=20la?= =?UTF-8?q?=20fuente?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- ConsoleMediaPlayer.Common/MediaPlayer.cs | 2 +- ConsoleMediaPlayer.VideoApp/Program.cs | 3 ++ ConsoleMediaPlayer.VideoApp/VideoPlayer.cs | 55 ++++++++++------------ 3 files changed, 29 insertions(+), 31 deletions(-) diff --git a/ConsoleMediaPlayer.Common/MediaPlayer.cs b/ConsoleMediaPlayer.Common/MediaPlayer.cs index c185f30..b7c37a1 100644 --- a/ConsoleMediaPlayer.Common/MediaPlayer.cs +++ b/ConsoleMediaPlayer.Common/MediaPlayer.cs @@ -14,13 +14,13 @@ public MediaPlayer(string filePath) if (!File.Exists(filePath)) throw new Exception($"El archivo {filePath} no existe"); FilePath = filePath; + ConsoleHelper.SetCurrentFont(FontSize); } public abstract void Play(); public void ResizeConsoleScreen() { - ConsoleHelper.SetCurrentFont(FontSize); int width = Resolution.Width + MARGIN.Width; int height = Resolution.Height + MARGIN.Height; Console.SetWindowSize(width, height); diff --git a/ConsoleMediaPlayer.VideoApp/Program.cs b/ConsoleMediaPlayer.VideoApp/Program.cs index 9fe2938..3efffc4 100644 --- a/ConsoleMediaPlayer.VideoApp/Program.cs +++ b/ConsoleMediaPlayer.VideoApp/Program.cs @@ -4,6 +4,9 @@ public class Program { public static void Main(string[] args) { + Console.WriteLine(Console.LargestWindowHeight); + Console.WriteLine(Console.LargestWindowWidth); + Console.WriteLine("Introduce ruta de un vídeo:"); string filePath = Console.ReadLine().Replace("\"", ""); diff --git a/ConsoleMediaPlayer.VideoApp/VideoPlayer.cs b/ConsoleMediaPlayer.VideoApp/VideoPlayer.cs index 1eae3f5..55ea3b6 100644 --- a/ConsoleMediaPlayer.VideoApp/VideoPlayer.cs +++ b/ConsoleMediaPlayer.VideoApp/VideoPlayer.cs @@ -16,7 +16,7 @@ public class VideoPlayer : MediaPlayer { private const int DEFAULT_HEIGHT = 250; private const int FPS_LIMIT = 24; - private static string ASCII_PIXEL_TABLE = @"█▓@8#x+o=:-. "; + private const string ASCII_PIXEL_TABLE = @"█▓@8#x+o=:-. "; private ISoundOut _soundOut; @@ -48,7 +48,7 @@ private void ExtractMetadata(int height) private int CalculateBytesPerFrame(int width, int height) { int lineSizeWithoutPadding = width * 3; - int lineSizeWithPadding = (int)Math.Ceiling(lineSizeWithoutPadding / 4f) * 4; + int lineSizeWithPadding = (int)Math.Ceiling(lineSizeWithoutPadding / 4.0) * 4; return 54 + lineSizeWithPadding * height; } @@ -82,9 +82,6 @@ public override async void Play() { Thread.Sleep(TimeSpan.FromTicks(waitTicks)); } - else - { - } } SpinWait.SpinUntil(() => _soundOut.PlaybackState != PlaybackState.Playing); @@ -108,33 +105,31 @@ await FFMpegArguments public async void ExtractFramesAsync() { - using (var stream = new MemoryTributary()) + using Stream stream = new MemoryTributary(); + + await FFMpegArguments + .FromFileInput(FilePath) + .OutputToPipe(new StreamPipeSink(stream), options => options + .ForceFormat("rawvideo") + .WithFramerate(FPS) + .WithVideoCodec("bmp") + .WithCustomArgument("-ss 00:00") + .Resize(Resolution.Width, Resolution.Height) + ).ProcessAsynchronously(); + + stream.Position = 0; + byte[] buffer = new byte[BytesPerFrame]; + Frames.Clear(); + + while (stream.Position < stream.Length) { - await FFMpegArguments - .FromFileInput(FilePath) - .OutputToPipe(new StreamPipeSink(stream), options => options - .ForceFormat("rawvideo") - .WithFramerate(FPS) - .WithVideoCodec("bmp") - .WithCustomArgument("-ss 00:00") - .Resize(Resolution.Width, Resolution.Height) - ).ProcessAsynchronously(); - - stream.Position = 0; - byte[] buffer = new byte[BytesPerFrame]; - Frames.Clear(); - - while (stream.Position < stream.Length) - { - int bytesReaded = stream.Read(buffer, 0, BytesPerFrame); + int bytesReaded = stream.Read(buffer, 0, BytesPerFrame); - using (MemoryStream auxStream = new MemoryStream(buffer, 0, bytesReaded)) - { - auxStream.Position = 0; - Bitmap frame = (Bitmap)Image.FromStream(auxStream); - Frames.Add(RenderFrame(frame)); - } - } + using MemoryStream auxStream = new MemoryStream(buffer, 0, bytesReaded); + + auxStream.Position = 0; + Bitmap frame = (Bitmap)Image.FromStream(auxStream); + Frames.Add(RenderFrame(frame)); } } From f2ec57ab9a4cef678b381eb88a10a1b689f2a18f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jos=C3=A9=20Santos=20Garrido?= Date: Thu, 20 Jul 2023 17:53:53 +0200 Subject: [PATCH 4/4] Create publish.yml --- .github/workflows/publish.yml | 46 +++++++++++++++++++++++++++++++++++ 1 file changed, 46 insertions(+) create mode 100644 .github/workflows/publish.yml diff --git a/.github/workflows/publish.yml b/.github/workflows/publish.yml new file mode 100644 index 0000000..f461168 --- /dev/null +++ b/.github/workflows/publish.yml @@ -0,0 +1,46 @@ +# This workflow will build a .NET project +# For more information see: https://docs.github.com/en/actions/automating-builds-and-tests/building-and-testing-net + +name: Publish + +# Declaring custom variables +env: + PROJECT_NAMES: ConsoleMediaPlayer.ImageApp ConsoleMediaPlayer.VideoApp + RELEASE_FOLDER: release + REPO_NAME: ${{ github.event.repository.name }} + +on: + workflow_dispatch: + release: + types: + - published + +jobs: + build: + # use ubuntu-latest image to run steps on + runs-on: ubuntu-latest + + steps: + # uses GitHub's checkout action to checkout code form the master branch + - uses: actions/checkout@v3 + + # Build project to the release-folder + - name: Build .NET Project + run: | + IFS=' ' read -ra projects <<< "${{ env.PROJECT_NAMES }}" + releaseFolder=${{env.RELEASE_FOLDER}} + for (( i=0; i<${#projects[@]}; i++ )); do + project=${projects[i]} + fullPath=${releaseFolder}/${project} + dotnet publish $project/$project.csproj -r -c Release -o $fullPath --nologo --self-contained true /p:PublishSingleFile=true /p:DebugType=None /p:DebugSymbols=false + cd $fullPath + zip -r ../${folder}.zip * + cd ../.. + done + + - name: Publish artifacts + uses: actions/upload-artifact@vv3.1.2 + with: + path: ${RELEASE_FOLDER}/*.zip + +