I failed to find a solution to the bug I asked about in another question: https://www.c-sharpcorner.com/forums/mediaelements-donsharp39t-work-as-expected
So, I decided to find a different way to run sound files. After some searching, I found a possible way.
I need to create a new WMPLib.WindowsMediaPlayer object, then assign it the relevant file path, which should be taken from the original media element.
- string path = music_path[vcoThis.Name.ToString()];
- wplayer_music.controls.stop();
- wplayer_music.URL = path.ToString();
- wplayer_music.controls.play();
This way, the sounds load and play correctly. However, this doesn't solve the problem fully.
1) First, it does work with audio, but doesn't work with video files. When loading a video file, I only hear relevant sound from it, but don't see any visual. Why that happens, and how it can be solved? I am not sure that I am right, but maybe I need to assign the width, height and margin to this WMPLib.WindowsMediaPlayer? If it's so, I can't find a way to assign new values.
I tried:
- WMPLib.WindowsMediaPlayer.width = 1600;
But I get error that there is no such definition. In my game, screen size can be different, depending on desired resolution, so I need to have an option to edit those values.
2) Second - many of MediaElements have events of "MediaOpened", "MediaEnded" and "MouseDown". Is there a way to "copy" those events to WMPLib.WindowsMediaPlayer?
I don't know the correct way to write it in code, so apologize for giving so "crude" example.
What I want:
- wplayer_music.MediaEndedEvent = vcoThis.MediaEndedEvent;
And what I don't want: let's consider that MediaEnded of vcoThis activates the void called "EndThisAudio".
I don't want it that way:
- wplayer_music.MediaEndedEvent = EndThisAudio();
Again, apologize for so ugly description. I mean, I want to take relevant events from "vcoThis", when both "vcoThis" can be different MediaElements, and they can have different events. Assigning one and same event \ void for all cases won't fit my needs.
Summary:
I need to understand how to:
1) Assign new width, height and margin to WMPLib.WindowsMediaPlayer
2) "Copy" relevant events from relevant MediaElement to WMPLib.WindowsMediaPlayer.