From f5a7e3ef7e25aa2545f541e171f2d5f6fe43ecc7 Mon Sep 17 00:00:00 2001 From: Andrew Lee Date: Mon, 8 Feb 2021 00:00:49 -0500 Subject: Erable playing audio in bg thread; Sirop backend initalized; Msgbox added --- Erable/ViewModels/MainWindowViewModel.cs | 48 ++++++++++++++++++++++++++------ 1 file changed, 39 insertions(+), 9 deletions(-) (limited to 'Erable/ViewModels/MainWindowViewModel.cs') diff --git a/Erable/ViewModels/MainWindowViewModel.cs b/Erable/ViewModels/MainWindowViewModel.cs index 0c51fbd..ab41886 100644 --- a/Erable/ViewModels/MainWindowViewModel.cs +++ b/Erable/ViewModels/MainWindowViewModel.cs @@ -1,7 +1,6 @@ -using System; -using System.Collections.Generic; -using System.Text; +using System.Threading; using Avalonia.Controls; +using Erable.Views; using Gst; namespace Erable.ViewModels @@ -10,9 +9,15 @@ namespace Erable.ViewModels { public string Greeting => "Welcome to Erable Audio Player!"; - public void PlayFunction(string[] args) + public void PlayFunction() { - Application.Init(ref args); + Thread t = new (AudioPlay); + t.Start(); + } + + static void AudioPlay() + { + Application.Init(); // Build the pipeline var pipeline = Parse.Launch("playbin uri=file:///home/andrew/Music/4616-werq-by-kevin-macleod.mp3"); @@ -24,13 +29,38 @@ namespace Erable.ViewModels var msg = bus.TimedPopFiltered (Constants.CLOCK_TIME_NONE, MessageType.Eos | MessageType.Error); // Free resources - //pipeline.SetState (State.Null); + pipeline.SetState (State.Null); + + } + + + public async void BrowseFunction() + { + var dialog = new OpenFileDialog(); + // dialog.Title + dialog.Filters.Add(new FileDialogFilter() {Name = "Audio Files", Extensions = {"mp3", "wav", "flac"}}); + dialog.Title = "Select Audio FIle"; + /* + var files = await dialog.ShowAsync(this); + + if(files != null && files.Length > 0) + { + var file = files[0]; + if (System.Runtime.InteropServices.RuntimeInformation.IsOSPlatform(System.Runtime.InteropServices.OSPlatform.Windows)) + { + PlayFunction($"file:/{file.Replace('\\', '/')}"); + } + else + { + PlayFunction($"file://{file}"); + } + }*/ } - public void BrowseFunction() + public void MsgBoxTest() { - //OpenFileDialog dialog = new OpenFileDialog(); - //dialog.Filters.Add(new FileDialogFilter() {Name = "Audio Files", Extensions = {"mp3"}}); + MessageBox.Show(new MainWindow(), "Hello world", "Test Title", MessageBox.MessageBoxButtons.Ok); } + } } -- cgit v1.2.3