Note that there are some explanatory texts on larger screens.

plurals
  1. POMediaPlayer MediaOpenned event is not firing on .net class
    primarykey
    data
    text
    <p>I'm trying to build a class where my thumbnail class is capturing a frame as a thumbnail of the videos users uploaded, things have gone good so far. I've written down the application on wpf app first and then decided to move to a class on my website as thumbnail.cs. Code is as shown below.</p> <p>My problem is, the MediaOpenned event doesn't fire up so the execution cannot continue as its supposed to, i tried calling it myself and put a thread.sleep to handle the delay with the buffering of video and the code worked as i wanted. But i don't want to rely on sleep since it can be unstable due to server and heavy.. I need it to work with the event or something similar like that.</p> <p>Any ideas or suggestions why event is not firing on .net? while working perfect on wpf? and what to do.</p> <p>And millions of thanks of course!</p> <p>thumbnail.cs class;</p> <pre><code> MediaPlayer myPlayer = new MediaPlayer(); public thumbnail() { myPlayer.Open(new Uri(@"C:\movie.wmv")); myPlayer.Play(); myPlayer.IsMuted = true; //this doesn't fire up myPlayer.MediaOpened += new EventHandler(myPlayer_MediaOpened); /* when i do like this it works as i want but unstable and heavy because sleep myPlayer_MediaOpened(null, null); System.Threading.Thread.Sleep(5000); */ } void myPlayer_MediaOpened(object sender, EventArgs e) { myPlayer.Position = TimeSpan.FromSeconds(myPlayer.NaturalDuration.TimeSpan.Seconds / 2); RenderTargetBitmap RenderTarBitmap = new RenderTargetBitmap(400, 300, 1 / 96, 1 / 96, PixelFormats.Pbgra32); DrawingVisual DVisual = new DrawingVisual(); DrawingContext DContext = DVisual.RenderOpen(); DContext.DrawVideo(myPlayer, new Rect(0, 0, 400, 300)); DContext.Close(); RenderTarBitmap.Render(DVisual); myPlayer.Stop(); BitmapFrame BMPFrame = BitmapFrame.Create(RenderTarBitmap); BitmapEncoder BMPEncoder = new JpegBitmapEncoder(); System.IO.FileStream FStream = new System.IO.FileStream(@"C:\movie.jpg", System.IO.FileMode.Create); BMPEncoder.Frames.Add(BMPFrame); BMPEncoder.Save(FStream); FStream.Flush(); FStream.Close(); } </code></pre> <h2>--------------------------------------------</h2> <p>UPDATE:</p> <p>Allright so i've been trying to solve this for days now and god knows the person going to help me is directly going to heaven! Anyway i found that i'm not able to fire any event handlers related to MediaPlayer or my thumbnail.cs (which is hosted in app_code and called by a asmx webservice).</p> <p>Tried some workarounds by using threads and implementing my own made event handlers checking whether movie is loaded or not.. no luck there either MediaPlayer doesn't let me touch its insides in another thread... And i didn't want to do more hack approach while able to solve with an easy event handler!</p> <p>Searched the deepest google, found a thread on 2006 that a person assumed it may be a problem with x64 (well i'm using x64) but i couldn't found anything about that on msdn and hell its been 5 years!</p> <p>So to sum up, i'm probably having a massive event not firing problem with either my class or my MediaPlayer control. And i need a saviour to help me catch the mediaOpenned event..</p> <p>Thank you again.</p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload