Results 1 to 3 of 3

Thread: MediaPlayer in ThinBasic form

  1. #1

    MediaPlayer in ThinBasic form

    I'm trying to use the Windows Media Player in ThinBasic (beta 1.8.6.0), I based my script on "ThinGames", also in this forum.

    I know that COM/ActiveX support is not complete, but I'm trying to understand why this script doesn't work with the latest Media Player. When I try to call any method or set property, the application crashes. Maybe it's a problem with threading or other...

    Any help?

     Uses "UI"
     Uses "COM"
      
     Declare Function UnregisterClass  Lib "USER32.DLL"  Alias "UnregisterClassA" (ByVal lpClassName As Asciiz, ByVal hInstance As DWord) As Long
     Declare Function GetModuleHandle  Lib "KERNEL32.DLL" Alias "GetModuleHandleA" (ByVal lpModuleName As Asciiz) As DWord
    
     Declare Function AtlAxWinInit Lib "ATL.DLL" Alias "AtlAxWinInit" () As Long
     Declare Function AtlAxGetControl Lib "ATL.DLL" Alias "AtlAxGetControl" (ByVal hControl As DWord, ByRef pObject As DWord) As Long 
    
     Function AtlAxWinTerm () As Long
      UnregisterClass ("AtlAxWin", GetModuleHandle(%NULL))
     End Function
     
     Dim Msg   As Long
     Dim wParam As Long
     Dim lParam As Long
     Dim hDlg  As Long
     Dim wx, hy As Long
      
     Dim hCtrl  As Long
    
     %Max_Param = 3
     Dim vParam(%Max_Param) As Variant
     
     %ID_OCX = 1001
     %ID_BUTTON = 1002
     
     Dim oMediaPlayer As DWord    
     
     $CLASS  = "WMPlayer.OCX"
     
     AtlAxWinInit
     
     Dialog New 0, "Media Player", -1, -1, 220, 300, %DS_CENTER, 0 To hDlg
     Control Add "AtlAxWin", hDlg, %ID_OCX, $CLASS, 10, 50, 200, 200, %WS_CHILD Or %WS_VISIBLE
     Control Add Button hDlg, %ID_BUTTON, "Play", 10, 10, 50, 25, Call onClick
    
     Dialog Get Client hdlg To wx, hy
    
     Control Set Resize hDlg, %ID_OCX, 1, 1, 1, 1
    
     Control Handle hDlg, %ID_OCX To hCtrl
     AtlAxGetControl(hCtrl, oMediaPlayer) 
     
     Dialog Show Modeless hDlg
     
     While IsWindow(hDlg)         
      Msg = GetMessage(hDlg, wParam, lParam)    
    
      Select Case Msg
    
       Case %WM_INITDIALOG     
    
       Case %WM_COMMAND
    
       Case %WM_SYSCOMMAND
        Select Case wParam
         Case %SC_CLOSE
          Exit While
        End Select 
    
       Case Else
       
      End Select
      
     Wend
    
     Dialog End hDlg
     AtlAxWinTerm
     
     CallBack Function onClick()
      If CBMSG = %WM_COMMAND Then
       Select Case CBCTLMSG
        Case %BN_CLICKED
         If CBCTL = %ID_BUTTON Then   
          vParam(1) = "http://www.mididatabase.com/20100702...e_Sedated.mid" 
          COM_EXECUTE(oMediaPlayer, "Url", %TB_DISPATCH_PROPERTYPUT, 1, vParam, 0)
         End If
       End Select
      
      End If
     End Function
    
    There is no bad programming language - only bad programmers

  2. #2
    Super Moderator Petr Schreiber's Avatar
    Join Date
    Aug 2005
    Location
    Brno - Czech Republic
    Posts
    7,128
    Rep Power
    732

    Re: MediaPlayer in ThinBasic form

    Hi Rocco,

    I am sadly not expert on COM, but if you like to render video inside dialog, you could use header file from here:
    MCI Video Wrapper

    COM module was developed by Roberto Biancchi, I hope he will come back to development some time in future, but I have no news from him.
    Eros had plan to take different approach on COM, using the "normal" dotted syntax, but when this will be completed I cannot say.

    I hope in the meantime the MCI solution could be of interest to you - it plays both video and music.

    For sound, there is also TBASS module, quite advanced one, based on famous BASS library.


    Petr
    Learn 3D graphics with ThinBASIC, learn TBGL!
    Windows 10 64bit - Intel Core i5-3350P @ 3.1GHz - 16 GB RAM - NVIDIA GeForce GTX 1050 Ti 4GB

  3. #3
    thinBasic MVPs
    Join Date
    May 2007
    Location
    UK
    Posts
    1,427
    Rep Power
    159

    Re: MediaPlayer in ThinBasic form

    Hello Rocco

    Here is a version of your script just using callbacks and with a quit option.

    I cant see what causes the crash but my knowledge of COM is near zero, is the value returned by "AtlAxGetControl(hCtrl, oMediaPlayer) " correct?

    can I also suggest using the Syntax Highlight (ThinBasic) when posting code as your previous post contained hidden characters.
    [code=thinbasic]
    Uses "UI","COM"

    Declare Function UnregisterClass Lib "USER32.DLL" Alias "UnregisterClassA" (ByVal lpClassName As Asciiz, ByVal hInstance As DWord) As Long
    Declare Function GetModuleHandle Lib "KERNEL32.DLL" Alias "GetModuleHandleA" (ByVal lpModuleName As Asciiz) As DWord

    Declare Function AtlAxWinInit Lib "ATL.DLL" Alias "AtlAxWinInit" () As Long
    Declare Function AtlAxGetControl Lib "ATL.DLL" Alias "AtlAxGetControl" (ByVal hControl As DWord, ByRef pObject As DWord) As Long

    Function AtlAxWinTerm () As Long
    UnregisterClass ("AtlAxWin", GetModuleHandle(%NULL))
    End Function

    Begin Const
    %Max_Param = 1
    %ID_OCX = 1001
    %ID_Play
    %ID_QUIT
    $myCLASS = "WMPlayer.OCX"
    End Const


    Dim Msg As Long
    Dim wParam As Long
    Dim lParam As Long
    Dim hDlg As DWord
    Dim wx, hy As Long
    Dim hCtrl As Long
    Dim vParam(%Max_Param) As Variant
    Dim oMediaPlayer As DWord


    AtlAxWinInit

    Dialog New 0, "Media Player", -1, -1, 220, 300, %DS_CENTER, 0 To hDlg

    Dialog Show Modal hDlg, Call dlgProc
    AtlAxWinTerm

    CallBack Function dlgProc()
    ' -- Test for messages
    Select Case CBMSG

    Case %WM_INITDIALOG

    Control Add "AtlAxWin", CBHNDL, %ID_OCX, $myCLASS, 10, 50, 200, 200, %WS_CHILD Or %WS_VISIBLE
    Control Add Button CBHNDL, %ID_PLAY, "Play", 10, 10, 50, 25, Call Play
    Control Add Button CBHNDL, %ID_QUIT, "QUIT", 70, 10, 50, 25, Call Quit
    Dialog Get Client CBHNDL To wx, hy
    Control Set Resize CBHNDL, %ID_OCX, 1, 1, 1, 1
    Control Handle CBHNDL, %ID_OCX To hCtrl
    AtlAxGetControl(hCtrl, oMediaPlayer)
    Case %WM_COMMAND
    Case %WM_TIMER
    Case %WM_CLOSE
    Case %WM_DESTROY

    End Select
    End Function

    CallBack Function Quit()
    If CBMSG = %WM_COMMAND And CBCTLMSG = %BN_CLICKED And CBCTL = %ID_QUIT Then
    Dialog End CBHNDL
    End If
    End Function

    CallBack Function Play()
    If CBMSG = %WM_COMMAND And CBCTLMSG = %BN_CLICKED And CBCTL = %ID_PLAY Then
    vParam(1) = "http://www.mididatabase.com/20100702...e_Sedated.mid"
    COM_EXECUTE(oMediaPlayer, "Url", %TB_DISPATCH_PROPERTYPUT, 1, vParam, 0)
    End If
    End Function

    [/code]
    Home Desktop : Windows 7 - Intel Pentium (D) - 3.0 Ghz - 2GB - Geforce 6800GS
    Home Laptop : WinXP Pro SP3 - Intel Centrino Duo - 1.73 Ghz - 2 GB - Intel GMA 950
    Home Laptop : Windows 10 - Intel(R) Core(TM) i5-4210U CPU @ 1.70GHz, 2401 Mhz, 2 Core(s), 4 Logical Processor(s) - 4 GB - Intel HD 4400
    Work Desktop : Windows 10 - Intel I7 - 4 Ghz - 8GB - Quadro Fx 370

Members who have read this thread: 0

There are no members to list at the moment.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •