visioforge / .Net-SDK-s-samples

VisioForge .Net SDKs samples - Video Capture SDK, Video Edit SDK, Media Player SDK, Media Blocks SDK, Video Fingerprinting SDK
https://www.visioforge.com
MIT License
50 stars 24 forks source link

No cdg and Async hangs WinUI 3 #15

Closed FatzBomb75 closed 1 year ago

FatzBomb75 commented 1 year ago

I've been looking for a relatively easy to use component for playing mp3+g, midi, audio & video files. I came across Media Player SDK and thought it might be perfect, but first wanted to try the demos (Been using Viscomsoft ActiveX for years, but it is not supported in WinUI, so seeking a new alternative) But alas, it seems the demos selectively work.

Everything appears to work normally in the WinForms karaoke demo as far as mp3+g is concerned (Didn't try the others as mp3+g is the main concern for me.)

The WPF demo works for MP4 and MP3 with sound but does not provide CDG information to the display.

Finally, my application uses WinUI 3 for Desktop, C#, and this demo fails nearly all the time. The first failure is it does not play sound as is for video files. Secondly, it does not play MP3 at all, nor CDG (Still launching mp3 as in the WinForms demo). Sometimes it does not play at all, the system seems to hang on the PlayAsync command, dead locking the UI. I noticed it never returns the task. This often happens with the first file I try but it is almost guaranteed with the second and future attempts. I use the same three files (MP4, MP3 and CDG) for all tests to verify it's not the files.

I reflected back to the WinForms & WPF samples to see if I could find something to change in WinUI. adding MediaPlayer1.Audio_PlayAudio = true; MediaPlayer1.Source_Mode = MediaPlayerSourceMode.File_DS; MediaPlayer1.Audio_OutputDevice = "Default DirectSound Device"; from the WinForms Karaoke demo into the WinUI method made no difference and it still hangs, never allowing a full test run.

I don't know if the issue lies in the demo, the component, or on my end, maybe I'm missing something (I run the demos as is).

(The project uses .NET 7)

visioforge commented 1 year ago

Hi

For CDG files use the WinForms demo as a code sample. CDG files are not supported by a generic engine.

I suggest using LAV source mode in your code.

WinUI demo issues are partially confirmed, we´ll provide an updated demo tomorrow.

visioforge commented 1 year ago

Demo update - https://github.com/visioforge/.Net-SDK-s-samples/tree/master/Media%20Player%20SDK/WinUI/CSharp/Simple%20Media%20Player%20WinUI

FatzBomb75 commented 1 year ago

This definitely helped in testing the app and with some modifications using the WinForms sample, I was able to get the cdg playing. There are still some issues with deadlocking, especially if hitting play again before stopping, when the file ends on its own, or when loading a non existing/unsupported file. I have put my own checking for this. I have but three questions, but since this is a bug forum, I understand if you are unable or wanting to answer.

  1. Is there a way to determine if an item is playing already (The element is playing content)
  2. In order to play the cdg to screen, I could not use video but added an Image control to my xaml and converted the bitmap to a stream to set it as shown below. Is this the best way, or is there a way to connect to the actual _cdg to the Image without converting or the videoView using the CDGFILE as this route seems to be overkill and quite intensive (Need to set timer to 10 or 20 for smooth playback)?
if (_cdg.renderAtPosition((long)(await MediaPlayer1.Position_Get_TimeAsync()).TotalMilliseconds))
                {
                    //videoView.PictureBoxSetImage((System.Drawing.Bitmap)_cdg.RGBImage(true));
                    BitmapImage bitmapImage = new BitmapImage();
                    using (MemoryStream stream = new MemoryStream())
                    {
                        _cdg.RGBImage(true).Save(stream, System.Drawing.Imaging.ImageFormat.Tiff);
                        stream.Position = 0;                        
                        bitmapImage.SetSource(stream.AsRandomAccessStream());
                    }
                    cdgImage.Source = bitmapImage;
                    _timer.Interval = TimeSpan.FromMilliseconds(20); // << Added just for live testing
                    //videoView.BackgroundImage_Source = bitmapImage;
                }
  1. These seem to have no effect setting before or after PlayAsync, I have tried multiple values:
            MediaPlayer1.Audio_Effects_PitchShift(0, null, 4);
            MediaPlayer1.Audio_Effects_Tempo(0, null, 5);

Thank you again for your fast responses, solutions, and hard work on this amazing library

visioforge commented 1 year ago

I agreed that the current code looks bad for real video playback. It was a very custom client that ask us to add this engine.

Please, give us 2-3 days to implement normal playback without a timer/custom thread.

FatzBomb75 commented 1 year ago

Will do and thank you, and for reference, the engine you built does work beautifully once implemented, very accurate even amongst seeking which is rare. Just a resource heavy implementation. An option to write as Image instead of Bitmap would be great for WinUI, so thank you. As a request, when you build another demo, a sample of integrating the pitch and tempo would be appreciated as they are most often used with cdg capabilities. I'll wait patiently :)

visioforge commented 1 year ago

I think you can use better code to convert bitmap without saving it to TIFF. For example, BMP, because we don't need any compression and TIFF, can cause performance issues.

Alternative engine - https://github.com/visioforge/.Net-SDK-s-samples/tree/master/Media%20Player%20SDK%20X%20(crossplatform)/WinForms/Karaoke%20Demo

The new demo does not use any Bitmaps.