Re: [Win32Lib] wrap Media control?
- Posted by mattlewis (admin) Feb 09, 2009
- 1157 views
ghaberek said...
This code works for me:
include Win32Lib.ew include wmp.ew without warning object PATH PATH = getenv("PATH") if sequence( PATH ) then PATH = w32split( PATH, ";" ) VOID = setSearchPaths( PATH ) end if constant icoMedia = extractIcon({ "wmp.dll", 7, 1 }) constant Main = create( Window, "Windows Media Player Demo", 0, Default, Default, 640, 480, 0 ) constant File = create( Menu, "&File", Main, 0, 0, 0, 0, 0 ) constant File_Open = create( MenuItem, "&Open...", File, 0, 0, 0, 0, 0 ) constant File_Sep1 = create( MenuItem, "-", File, 0, 0, 0, 0, 0 ) constant File_Exit = create( MenuItem, "E&xit", File, 0, 0, 0, 0, w32AUTOCLOSE ) constant WMPlayer = create_com_control( WindowsMediaPlayer_clsid_ix, getHandle(Main), 0, 0, 0, 0 ) constant Controls = ref_com_object( IWMPControls3_clsid_ix, invoke( WMPlayer, {WMPCore_p_controls}, {}, {}, DISPATCH_PROPERTYGET ) ) constant Playlist = ref_com_object( IWMPPlaylist_clsid_ix, invoke(WMPlayer, {WMPCore_p_currentPlaylist}, {}, {}, DISPATCH_PROPERTYGET ) ) setIcon( Main, icoMedia ) com_err_out( 1 ) procedure Main_onResize( integer pSelf, integer pEvent, sequence pParams ) sequence rect rect = getClientRect( pSelf ) move_obj( WMPlayer, rect[1..4] ) end procedure setHandler( Main, w32HResize, routine_id("Main_onResize") ) function new_media( sequence url ) atom bstr integer media object void bstr = alloc_bstr( url ) media = ref_com_object( IWMPMedia_clsid_ix , invoke( WMPlayer, { WMPCore_m_newMedia }, {bstr}, {VT_BSTR}, DISPATCH_METHOD ) ) free_bstr( bstr ) void = invoke(Playlist, {IWMPPlaylist_m_appendItem}, {get_obj_this(media)}, {VT_UNKNOWN}, DISPATCH_METHOD ) return media end function procedure play_media( integer media ) object void void = invoke( Controls, {IWMPControls3_m_playItem}, {get_obj_this(media)}, {VT_UNKNOWN}, DISPATCH_METHOD ) end procedure procedure File_Open_onClick( integer pSelf, integer pEvent, sequence pParams ) sequence filename atom bstr integer media filename = getOpenFileName( Main, "", {"All files (*.*)", "*.*"} ) if length( filename ) = 0 then return end if media = new_media( "file:///" & filename ) play_media( media ) end procedure setHandler( File_Open, w32HClick, routine_id("File_Open_onClick") ) WinMain( Main, Normal ) release_com()
Matt