c# - MediaElement possible memory leak on new media load? -


i developing wpf app media player in c# , using mediaelement control host media.

as want user able load both video , images in player, ve made simple if-then-else statement inside mediaopened event, check every time new media loaded, if hastimespan (and therefor player sees video) or else picture.

to check if if/else statement working, placed message box in each case give me feedback indeed player recognizes correctly media type.

so far good.

i load video, goes expected , message box saying "video!".

but when load 2nd video message box appears 2 times.

when load 1 more video, message box appears 3 times!

even weirder, if load picture next, message box appears 4 times instead of sequence of message boxes this,

"video!" "video!" "video!" "picture!",

"picture!" "picture!" "picture!" "picture!".

it seems player storing media (or mediaopened events) in kind of list , every time load new one, checks media in list , gives me message each one. (i haven't wrote code support playlist feature yet, don't know these media being stored...)

i ve tried stating mediaelement's source null when user presses load new media button, make sure mediaelement source clean before new media gets loaded, did not have effect.

does sound memory leak? missing specific unloading event should call upon media change? thank you!

so turns out in online examples on how develop mediaplayer,

everybody suggests using next line upon clicking load button in player:

mediaelement.mediaopened += new routedeventhandler(mediaelement_mediaopened);

but no 1 seems aware these media need unloaded when load new one, possible placing exact opposite, before set new source of media element, in order example:

mediaelement.mediaopened -= new routedeventhandler(mediaelement_mediaopened);

mediaelement.source = new uri(dlg.filename);

mediaelement.mediaopened += new routedeventhandler(mediaelement_mediaopened);

hope helps out there!


Comments

Popular posts from this blog

asp.net mvc - SSO between MVCForum and Umbraco7 -

Python Tkinter keyboard using bind -

ubuntu - Selenium Node Not Connecting to Hub, Not Opening Port -