Jump to content
Tuts 4 You

MediaPlayer


fearless

Recommended Posts

fearless
Posted (edited)

A basic media player application written in x86 and x64 assembler that utilizes the MFPlayer-Library - which consists of functions that wrap the MFPlay COM implementation of the IMFPMediaPlayer and IMFPMediaItem objects.

https://github.com/mrfearless/MediaPlayer

mediaplayer_75.png.928af227404e3e0e9d2347f1b94023f1.png

Features

  • Supports audio and video media that is natively supported by the Microsoft Media Foundation API
  • Player controls via toolbar buttons, menu or context menu: Play/Pause Toggle, Stop, Frame Step, Volume Mute/Unmute, Fullscreen toggle, About, Exit.
  • Custom control for Volume slider.
  • Custom control for Seekbar slider.
  • Custom controls for Labels (for duration of media and current position).
  • Fullscreen enter via toolbar button, menu, context menu or F11.
  • Fullscreen exit via toolbar button, menu, context menu, F11 or Escape.
  • Spacebar toggles play/pause.
  • Open media via File menu, context menu, clicking screen logo, clicking play button or drag and drop.
  • Uses the FileDialog-Library

Download

The latest releases can be downloaded at https://github.com/mrfearless/mediaplayer/releases
 

Edit: Attached v1.0.0.5 releases.

 

 

MediaPlayer-x64.zip MediaPlayer-x86.zip

Edited by fearless
Update screenshot
  • Like 3
  • Thanks 4
jackyjask
Posted

kudos!

this is definitely a masterpiece SW

such a rare moment of x64 assembly based fine piece of great code

  • Like 3
Posted

I have loved this particular media player. The only thing missing is the option to delete the history opened files.

  • Like 2
whoknows
Posted

@fearless - no words!!!!!!!!!!!!!!!!

 

good to have @ :

  • at fullscreen the timeline to get hidden, on mouse move visible again
  • support of .srt :partytime:

 

  • Like 3
Posted
8 hours ago, whoknows said:

@fearless - no words!!!!!!!!!!!!!!!!

 

good to have @ :

 

  • support of .srt :partytime:

 

Also this

Posted

Hi @fearless,

thanks for the new source. :) So before I try to implement the new code parts into my code and I have a small question. So I see you made already an working media player and I would like to know whether it could be possible to implement the almost entire media player source of yours into another source without doing much changes / adjustments etc?

So I would like to put your media player GUI into an custom window / static control. Something like player GUI on static control which is captured on that control and from my source I just want to send the media path / URL into to let them play. Do you know what I mean? So in that case I would save the work to adjust all my code using the player code and my controls to handle those media files. Somehow like a app in a app. Is that doable anyhow? Important is that your app GUI is captured into my app (not running extern) window / control (boxed) to run this one instance only. Is that doable (if yes / how could that be done) or not?

greetz

  • Like 1
fearless
Posted

It would need to be all encapsulated as a single custom control that takes most of what is in the media player app and places it in its own window. A lot of the logic of the media player app is based on the fact that the parent window is the main window, with a proper message loop. Its possible to do, but a lot of work. The basis for doing all that work is in the MediaPlayer example itself. Essentially you would create your own custom container window (not a static control), and then create the various parts of the media player as children of that main container window. More work would probably be needed to properly "communicate" back and forth with the MediaPlayer control in an elegant manner with message handling, notifications etc.

  • Like 2
jackyjask
Posted

Just wondering!

in the ResHacker one could see a beautiful Planet Earth - 

image.png.1f2b98e15cd62343827bbd3cc8d19676.png

 

but in reality it shows another pic

is it kind of Easter Egg? :)

 

  • Like 2
fearless
Posted

I think its just ResHacker showing a generic icon in place of a SS_ICON style static control, as the icon hasnt been loaded/set into the static yet. There is another one on the main dialog as well, which I should remove as its no longer used and is disabled/not visible by default.

  • Like 3
  • Thanks 1
Posted

Another question. Is it possible to make some kind of build in bundle of some player functions? I mean so that the end user can use the player easily without to handle all those steps in callback / routines etc?

Idea: I just want to use your player instance (working player + some button functions) in my app to play desired media files. All I have made is an static control for the video output and some navigation buttons to play / pause / stop / seek bar / duration time. Now I would like to register the buttons & static handle with your player bundle like...

Init MPlayer (once only)
Init Play Button
Init Stop Button
Init Pause Button
Init Seek Control
etc

...so that your code also does handle those actions (internal) when I click on them. Only thing what I have to do is sending the media path via a API function the player should work with. Maybe sounds strange so far but would be more simple and easier to use. Otherwise its harder to find all functions / routines I need to use / adjust from your media player example code you know.

PS: Do you have some advice to get an better overview of your code to make some simple working examples?

greetz

jackyjask
Posted

maybe you also need to call some callbacks on the buttons? 

and callback will call your registered routines that will do extra work

fearless
Posted

The MFPlayer.lib library handles the basics of the MFPlay player. The rest is all the GUI stuff I put in place around that. If you look at GUIInit in the MediaPlayer example you will see that I initialize a lot of the stuff there, create the windows and controls required, and they have been separated into there own files for easier organization and access. The controls dialog hosts a couple of toolbars, which are initialized when the dialog is created with the _MPCInit function from WM_INITDIALOG. All the icons, imagelists, toolbars, toolbar buttons are all created and assigned there. All the processing is then done in the dialog procedure MediaPlayerControlsProc. And similarly with the other controls. There is some exceptions and some globals variables used throughout to help with getting the whole thing to work.

The MFPMediaPlayer_Init function: https://mfplayer-library.readthedocs.io/en/latest/MFPlayer Functions/MFPMediaPlayer Functions/MFPMediaPlayer_Init.html#mfpmediaplayer-init, is the initial one off initialization of the the IMFMediaPlayer object. The event notification callback function is needed to handle all the events that happen when using the MFPlay functions.

To load a media file for the IMFMediaPlayer object to play it, you can call the MFPMediaPlayer_CreateMediaItemA/W (Ansi or Wide version): https://mfplayer-library.readthedocs.io/en/latest/MFPlayer Functions/MFPMediaPlayer Functions/MFPMediaPlayer_CreateMediaItemA.html, or https://mfplayer-library.readthedocs.io/en/latest/MFPlayer Functions/MFPMediaPlayer Functions/MFPMediaPlayer_CreateMediaItemW.html

In the MediaPlayer example when using those CreateMediaItem functions, the event callback function (MFP_OnMediaPlayerEvent) will receive the MFP_EVENT_TYPE_MEDIAITEM_SET event, where I get the duration of the media file, set the labels to display the position and duration and then call the Play function. MFP_OnMediaPlayerEvent will then receive the MFP_EVENT_TYPE_PLAY event then (and when user clicks play button or play menu items) and starts the seekbar timer and updates the toolbar controls (toggle play/pause icon for example)

There is no easy way to implement this as a single control without a lot of work. The MediaPlayer is the most basic example that there is to implement the MFPlayer.lib functions, and thus the COM methods in the IMFPMediaPlayer and IMFPMediaItem objects.

Your example of: Init MPlayer (once only) Init Play Button Init Stop Button Init Pause Button Init Seek Control is already implemented in the GUIInit function

 

  • Like 2
Posted (edited)

v1.0.0.1

https://github.com/mrfearless/MediaPlayer/releases/tag/1.0.0.1

  • Changed default codebase for x86 and x64 MediaPlayer to use wide/unicode for better handling and display of unicode filenames #2 #3.
  • Ini file now is created with BOM to allow unicode - for MRU filenames.
  • Ini file prepends a play/pause unicode glyph to its name (helps indicate that it is unicode perhaps?)
  • Add clear recent files option (comment/wish from BOSCH on Tuts4you).
  • Fix memory leak - missing DragFinish call  #4.
  • Fix transparent painting issue in about dialog box #1.
  • Added use of ChangeWindowMessageFilter to better support drag and drop for UAC blocking drag and drop operations #4.
  • Added play rate (slower/faster) buttons and menu items (request from Yashar Mahmoudnia on Tuts4you Telegram).
  • Added step 10 seconds (backward/forward) buttons and menu items.
  • Add additional accelerators for play rate and step 10 options.
  • Add missing accelerator resource for x64 version (Thanks to jj2007).
  • Combined toolbars to just one toolbar now.

Edit: Fix small crash in x64 version when using slow/fast buttons or menu option - ebx instead of rbx in event notification callback - proper x64 version attached now

MediaPlayer-x86.zip

MediaPlayer-x64.zip

Edited by fearless
bugfix x64
  • Like 4
  • Thanks 3
jackyjask
Posted

I'd say your release definitely deserve 1.1.0.0 :) (major.minor.patch.revision as in semver encoding schemata)

(just kidding)

very ool stuff! thanks!

  • Like 3
Posted
21 hours ago, fearless said:
  • Add clear recent files option (comment/wish from BOSCH on Tuts4you).

I have no words to thank you. Thank you very much.

Immediate software support and fast. Something you can't find in the software of companies that I have paid software licenses for.

 

Just a question. Why windows defender detect latest version 1.0.0.1 as Trojan:Win32/Wacatac.H!ml?

In previous version i don't have this detection.

  • Like 1
Posted (edited)

Great software, very lightweight. Thanks for sharing!

image.png

Edited by kuazi GA
Posted
1 hour ago, BOSCH said:

Why windows defender detect latest version 1.0.0.1 as Trojan:Win32/Wacatac.H!ml?

I'm not sure, I scanned both versions myself on Win10 with Windows Defender and it didn't show up anything. I uploaded both to VirusTotal anyhow and made a comment on them both linking to the open source github repo, just in case. Only 1 engine out of 75 reporting something, so not sure why you are getting that trigger.

  • Like 1
jackyjask
Posted

@fearless there is some strange case when player will continue count current time (left counter) endlessly, but I can't figure it out what are the exact steps, sorry...

Posted

Hey fearless,

thanks for the info but I don't get it (still!). Could you maybe first just post some simple way of APIs I need to call to get any video playing?


		invoke GetDlgItem,hWin,IDC_Playerwindow	; static controk with ss_notify 
		mov hMediaPlayerWindow, eax
		Invoke MFPMediaPlayer_Init, hMediaPlayerWindow, Addr MFP_OnMediaPlayerEvent, Addr pMP ; init

WM_COMMAND
		.elseif ax == IDC_PLAY
			Invoke MFPMediaPlayer_CreateMediaItem, pMP, chr$("C:\WinAsm\MFPlayer_Test\SampleVideo_1280x720_1mb.mp4"), 0, Addr pMI

How has the callback routine look like (clean without your extra stuff)? So I create player window (static) and just few buttons by myself without to use your controls or init them etc. Maybe you can explain this a little (safe for dummies) just to get anything work so far. Thank you.

greetz

Posted
2 hours ago, jackyjask said:

@fearless there is some strange case when player will continue count current time (left counter) endlessly, but I can't figure it out what are the exact steps, sorry...

Thanks for letting me know. A user on the github repo reported the same issue: https://github.com/mrfearless/MediaPlayer/issues/6

I was thinking about what could be causing it before I even looked at the github repo, and logically thought that as the seekbar timer is still firing then somehow the media engine in the MFPlay COM stuff still thinks that there is something to "play". As the timer starts when user clicks Play (or menu or loads a file/drops a file), and only stops when user clicks Stop, OR when the duration of the media item is reached - in that case the event handler receives an end of playback notification, and i also call stop on the engine then as well, and stop the timer. Somehow that was being bypassed, so I figured that the time skip feature was a likely culprit.

I assumed the media engine would internally check positions > duration, but obviously it doesn't and probably only checks if position = duration. Skipping at the end of the media item, sends the position past the duration (so no position = duration is met) and media engine thinks there is stuff to play, so keeps incrementing frames and position. As the event handler never gets the end of playback event, the timer is never stopped either, so it keeps getting the position and updating the label.

I will introduce my own checks for that in the next update, which hopefully fixes that.

  • Like 2
  • Thanks 1
jackyjask
Posted

Amazing findning!

new day -another challange!

 

image.png.73214176e12c9a0b426e3228d46d91ca.png  KUDOS!

  • Thanks 1
Posted

v1.0.0.2

https://github.com/mrfearless/MediaPlayer/releases/tag/1.0.0.2

  • Clicking middle logo now toggles between play/pause (for audio playback).
  • Removed double click option on main window.
  • Moved F11 fullscreen toggle to accelerator table instead of WM_KEYDOWN.
  • Fix menu activation not working when pressing Alt key + menu key (IsDialogMessage was the culprit) #7.
  • Fix for stepping past duration of media file with play speed increase and step 10 #6.
  • Fix for SeekBar position still showing after end of media when play speed is increased #6.
  • Added EN, DE, FR, PL, IT languages using google translate (any mistakes let me know, or requests for languages).
  • Added language menu item on menu bar and loading menus based on language selection.
  • Made language specific versions of main menu.
  • Moved context menu to language specific versions.
  • Language setting saved in ini file, and applied when starting MediaPlayer.
  • Moved strings (tooltips etc) to string table resource for language change processing.

MediaPlayer-x64.zip MediaPlayer-x86.zip

  • Like 1
  • Thanks 2
jackyjask
Posted

well done!

but ... you get + 20KB :) (x64 binary)

 

 

quick quesiton on resources -  (1.0.0.2)

image.png.5eccfa9527bb334bf93660b9d980852e.png

Posted

I dont see any questions, just the image, with numbers. Assuming its in relation to the highlighted string table:

I set the string table to english_us, as it shouldnt matter when using LoadString. Without the lang entry, it was showing the last lang entry from one of the menus, so when i spotted that in resource hacker, i added the lang entry to the string table.

Otherwise the  entries shown in 1 and 2 are other language entries for main menu ID 10000 or context menu ID 11000.

Posted

@fearless

Could you tell me how to create & use a seekbar control? So I got it working to handle open/play/stop/pause so far but I also wanna have a working seekbar & duration times for start / origin time & full time. I got really problems using your sources to build anything simple new etc. Maybe you can help with that again to get something here in action. Thanks.

greetz

  • Like 1

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
×
×
  • Create New...