:Start of VDSWMP VDSWmp.dsc
DragonSphereSoftware

DragonSphere Software Demos


If you are viewing this script in your browser you can save it as a VDS 5.x source file (*.dsc) to run it.




#
# DragonSphere Software's Home Page
#  
# All Source Files for this demo
#
# This demo hosts the MS Windows Media Player
# To use this demo you drag media files(ie... *.avi,*.mp3,*.wmp, and etc..)
# to the VDS dialog.
# The demo uses Media Player's built in play list to manage the medai files
# Side note:  The demo uses Gadget's built in sleep timer and shows the usage
#             of the command Gadget VDSHasEvents,ALL
#
#OPTION ERRORTRAP,ONERROR
Title VDS Windows Media Player
OPTION SCALE, 96 
OPTION DECIMALSEP, "." 

If @Greater(@Name(@SYSINFO(DSVER)),4)


External GadgetX.dll,@SYSINFO(DSVER)

  #DEFINE COMMAND,GADGETX,DEFINE,SET,SLEEP,VDSHASEVENTS,OLE,CALL
  #DEFINE FUNCTION,GADGETX,GET,GETVAR,OLE,CALL,GETLASTERROR
  #DEFINE COMMAND,OpenStateChange
  #DEFINE COMMAND,PlayStateChange
Else
  Warn This demo will only work with VDS 5+
  Stop
End


# Ole true and false
Define Constant,OLE_TRUE,-1
Define Constant,OLE_FALSE,0

# State of playback
# Please select one of these constants from the table for usage.

# WMPPlayState
# State is undefined
Define Constant,wmppsUndefined,0
# Playback is stopped
Define Constant,wmppsStopped,1
# Playback is paused
Define Constant,wmppsPaused,2
# Stream is playing
Define Constant,wmppsPlaying,3
# Stream is Scanning forward
Define Constant,wmppsScanForward,4
# Stream is Scanning in reverse
Define Constant,wmppsScanReverse,5
# Media is being buffered
Define Constant,wmppsBuffering,6
# Waiting for streaming data
Define Constant,wmppsWaiting,7
# End of media reached
Define Constant,wmppsMediaEnded,8
# Preparing new media
Define Constant,wmppsTransitioning,9
# Ready to begin playing
Define Constant,wmppsReady,10
# Trying to reconnect for streaming data
Define Constant,wmppsReconnecting,11
# Last playstate
Define Constant,wmppsLast,12

# WMPOpenState
# Undefined
Define Constant,wmposUndefined,0
# New Playlist is about to be loaded
Define Constant,wmposPlaylistChanging,1
# Locating the playlist
Define Constant,wmposPlaylistLocating,2
# Connecting to the server holding a playlist
Define Constant,wmposPlaylistConnecting,3
# Loading a playlist
Define Constant,wmposPlaylistLoading,4
# Opening a playlist
Define Constant,wmposPlaylistOpening,5
# Playlist is open
Define Constant,wmposPlaylistOpenNoMedia,6
# Playlist has changed
Define Constant,wmposPlaylistChanged,7
# New media is about to be loaded
Define Constant,wmposMediaChanging,8
# Locating the media
Define Constant,wmposMediaLocating,9
# Connecting to the server holding media
Define Constant,wmposMediaConnecting,10
# Loading media
Define Constant,wmposMediaLoading,11
# Opening a media
Define Constant,wmposMediaOpening,12
# Media is open
Define Constant,wmposMediaOpen,13
# Starting codec acquisition
Define Constant,wmposBeginCodecAcquisition,14
# End codec acquisition
Define Constant,wmposEndCodecAcquisition,15
# Starting license acquisition
Define Constant,wmposBeginLicenseAcquisition,16
# End license acquisition
Define Constant,wmposEndLicenseAcquisition,17
# Starting individualization
Define Constant,wmposBeginIndividualization,18
# End individualization
Define Constant,wmposEndIndividualization,19
# Waiting for media
Define Constant,wmposMediaWaiting,20
# Opening an URL whose type is not known
Define Constant,wmposOpeningUnknownURL,21

# Objects needed
Define Variable,Object,WMP
Define Variable,Object,MyPlayList
Define Variable,Object,MyMedia
Define IID,WMPOCXEvents,{6BF52A51-394A-11D3-B153-00C04F79FAA6}

# Gadget VDSHasEvents flags
Define Constant,KEY,$1
Define Constant,MOUSEMOVE,$2
Define Constant,MOUSEBUTTON,$4
Define Constant,POSTMESSAGE,$8
Define Constant,TIMER,$10
Define Constant,PAINT,$20
Define Constant,SENDMESSAGE,$40
Define Constant,HOTKEY,$80
# For debugging turn on Exceptions
# Ole Exceptions,HIDE
# Initialize OLE This is required for any application to use ActiveX controls.
Ole Init
%%NewState = 0


# Create the Media Player object and save it to the Gadget WMP object

#Set WMP,@Ole(Create,WMPlayer.OCX.7,NULL)


# Gets the pixels from inches
# This allows our media player to display a 
# wide screen 9" wide X 6" heigh just like many portable DVD players.
%%Width = @Prod(@Sysinfo(PIXPERIN),7)
%%Height = @Prod(@Sysinfo(PIXPERIN),4)

%%winclass = "#WMP"
  DIALOG CREATE,VDS Windows Media Player,-1,0,%%Width,%%Height,CLASS WMP,DRAGDROP,PAINT,RESIZABLE
  DIALOG ADD,MENU,View,Full Screen,All Controls,Mini Controls,No Controls
REM *** Modified by Dialog Designer on 9/11/2005 - 17:54 ***
  # Add WMP to the VDS dialog
  # GadgetX Add,OLE,,,,,,,
  GADGETX ADD,OLE,WMP,%%winclass,0,0,@dlgpos(,W),@diff(@dlgpos(,H),19),WMPlayer.OCX
  DIALOG ADD,STATUS,STATUS1,[90]|[160]
  DIALOG SHOW
%%WinTitle = VDS Windows Media Player

# Set some simple properties just to get started
List create,1 
List LoadText,1
"uiMode=full
"enabled=True
"enableContextMenu=True
"windowlessVideo=False
"stretchToFit=True
"shrinkToFit=True

# Sets multiple properties at one time from the list above
# NOTE: The properties should be simple types (ie...base number types and strings)
#       pointers may not work and should be tested throughly.
Ole SetPropertyList,WMP,@Text(1)
List Clear,1

# Or you can set them 1 at a time.
#Ole SetProperty,WMP,uiMode = ^B,mini
#Ole SetProperty,WMP,enabled = ^B,True
#Ole SetProperty,WMP,windowlessVideo = ^B,True
#Ole SetProperty,WMP,enableContextMenu = ^B,True
#Ole SetProperty,WMP,stretchToFit = ^b,OLE_FALSE

# Call the method to create a new Play List
Set MyPlayList,@Ole(Call,WMP,"^o","newPlaylist(^B,^B)","vdsdefault","")

# Assign the new play list to WMP
Ole Set,WMP,"currentPlaylist = ^o",MyPlayList
# Setup the events
Define EventMap,WMPOCXEvents,OpenStateChange,5001
Define EventMap,WMPOCXEvents,PlayStateChange,5101
%%token = @Ole(ConnectEvents,WMP,WMPOCXEvents)
 %%cnt = 0
%%NewState =
%%Panel1 =
%%Panel2 =
%%Panel3 =

:evloop
  # Use Gadget's built in sleep timer for this
  # so the objects window will repaint quicker
  # and the dialog will respond faster to user input
  Sleep 10
  #WAIT EVENT,0.3
  %E = @event()
  If %E
    goto %E
  End
GOTO EVLOOP  
:TIMER
  # If the dialog does not need to be repainted or if the user has not clicked
  # one of the buttons then show the time left for the media to play
  # This allows us to do alot of work with out causing so much delay in the response
  # of the dialog.
 If @Equal(%%NewState,3)
    %%Time = @Ole(Get,WMP,^g,controls.currentPosition)
    If %%Time
      %%TimeNow = @Format(%%Time,5.3)
      %T = @Ole(Get,WMP,^g,currentMedia.duration)
      If %T
        %%Duration = @Format(%T,5.3)
        %%SecLeft = @Fsub(%%Duration,%%TimeNow)
        %%MinLeft = @Format(@FDiv(%%SecLeft,60),5.3)
        %%Panel2 = Time Remaining: @Name(%%MinLeft):@Ext(%%MinLeft)
      End
    End
  End
  DIALOG Set,Status1,%%Panel1@Tab()%%Panel2@Tab()%%Panel3
  Dialog Title,%%WinTitle %%Panel1 %%current  
GOTO EVLOOP
:RESIZE
:PAINT
  Ole SetPos,WMP,%%winclass,0,0,@dlgpos(,W),@diff(@dlgpos(,H),19)
goto evloop
:Mini Controlsmenu
  Ole Set,WMP,uiMode = ^B,mini
goto evloop
:All Controlsmenu
  Ole Set,WMP,uiMode = ^B,full
goto evloop
:No Controlsmenu
  Ole Set,WMP,uiMode = ^B,invisible
goto evloop
:Full Screenmenu
  If @Equal(@Ole(Get,WMP,^d,playState),3)
    Ole Set,WMP,fullScreen = ^B,True
  End
goto evloop
:DRAGDROP
 # Note: You can also drop URL's unto the dialog and if the URL points to a media file
 #       Media Player will download the file and play it.
 List dropfiles,1
 %%cnt = 0
 %%cntmp3s = @count(1)
 repeat
   %%URL = @Item(1,%%cnt)
   If %%URL
     Set MyMedia,@Ole(Call,WMP,"^o","newMedia(^B)",%%URL)
     If @Get(MyMedia)
       Ole Call,MyPlayList,"appendItem(^o)",MyMedia
     End
   End
   %%cnt = @Succ(%%cnt)
 Until @Equal(%%cnt,%%cntmp3s)
 wait
 Ole Call,WMP,"Controls.play"
 Ole SetPos,WMP,%%winclass,0,0,@dlgpos(,W),@diff(@dlgpos(,H),19) 
 List clear,1
goto evloop
:WMPOCXEventsOpenStateChange
  %%OpenState = @Trim(@Ole(EventParamsList,WMPOCXEventsOpenStateChange))
  # Dialog Set,STATUS1,%%OpenState@Tab()
  # WMPOpenState
  If @Equal(%%OpenState,@Get(wmposUndefined))
    # Undefined
    %%Panel3 = Undefined
  ElsIf @Equal(%%OpenState,@Get(wmposPlaylistChanging))
    # New Playlist is about to be loaded
    %%Panel3 = New Playlist
  ElsIf @Equal(%%OpenState,@Get(wmposPlaylistLocating))
    # Locating the playlist
    %%Panel3 = Locating Playlist
  ElsIf @Equal(%%OpenState,@Get(wmposPlaylistConnecting))    
    # Connecting to the server holding a playlist
    %%Panel3 = Connecting to Server
  ElsIf @Equal(%%OpenState,@Get(wmposPlaylistLoading))        
    # Loading a playlist
    %%Panel3 = Loading Playlist
  ElsIf @Equal(%%OpenState,@Get(wmposPlaylistOpening))
    # Opening a playlist
    %%Panel3 = Opening Playlist
  ElsIf @Equal(%%OpenState,@Get(wmposPlaylistOpening))
    # Playlist is open
    %%Panel3 = Playlist opened
  ElsIf @Equal(%%OpenState,@Get(wmposPlaylistOpenNoMedia))
    # Playlist is open
    %%Panel3 = NoMedia
  ElsIf @Equal(%%OpenState,@Get(wmposPlaylistChanged))
    # Playlist has changed
    %%Panel3 = Playlist Changed
  ElsIf @Equal(%%OpenState,@Get(wmposMediaChanging))
    # New media is about to be loaded
    %%Panel3 = Media Changing
  ElsIf @Equal(%%OpenState,@Get(wmposMediaLocating))
    # Locating the media
    %%Panel3 = Media Locating
  ElsIf @Equal(%%OpenState,@Get(wmposMediaConnecting))
    # Connecting to the server holding media
    %%Panel3 = Media Connecting
  ElsIf @Equal(%%OpenState,@Get(wmposMediaLoading))
    # Loading media
    %%Panel3 = Media Loading
  ElsIf @Equal(%%OpenState,@Get(wmposMediaOpening))    
    # Opening a media
    %%Panel3 = Media Opening
  ElsIf @Equal(%%OpenState,@Get(wmposMediaOpen))    
    # Media is open
    %%Panel3 = %%current
  ElsIf @Equal(%%OpenState,@Get(wmposBeginCodecAcquisition))    
    # Starting codec acquisition
    %%Panel3 = Begin Codec Acquisition
  ElsIf @Equal(%%OpenState,@Get(wmposEndCodecAcquisition))
    # End codec acquisition
    %%Panel3 = End Codec Acquisition
  ElsIf @Equal(%%OpenState,@Get(wmposBeginLicenseAcquisition))    
    # Starting license acquisition
    %%Panel3 = Begin License Acquisition
  ElsIf @Equal(%%OpenState,@Get(wmposEndLicenseAcquisition))
    # End license acquisition
    %%Panel3 = End License Acquisition
  ElsIf @Equal(%%OpenState,@Get(wmposBeginIndividualization))
    # Starting individualization
    %%Panel3 = Begin Individualization
  ElsIf @Equal(%%OpenState,@Get(wmposEndIndividualization))
    # End individualization
    %%Panel3 = End Individualization
  ElsIf @Equal(%%OpenState,@Get(wmposMediaWaiting))
    # Waiting for media
    %%Panel3 = Media Waiting
  ElsIf @Equal(%%OpenState,@Get(wmposOpeningUnknownURL))
    # Opening an URL whose type is not known
    %%Panel3 = Opening Unknown URL
  End
  
goto evloop
:WMPOCXEventsPlayStateChange
  # If the dialog does not need to be repainted or if the user has not clicked
  # one of the buttons then show the time left for the media to play
  # This allows us to do alot of work with out causing so much delay in the response
  # of the dialog.
  VDSHasEvents ALL
  If @OK()
   # wait
    goto evloop
  End
  %%NewState = @Ole(EventParamsList,WMPOCXEventsPlayStateChange)

  %%current = @Ole(Get,WMP,^B,currentMedia.name)
  If @Equal(%%NewState,@Get(wmppsStopped))
    %%Panel1 = Stopped
    %%current =
    #%%Panel3 = %%current
  ElsIf @Equal(%%NewState,@Get(wmppsPaused))
    %%Panel1 = Paused
    %%current =
    #%%Panel3 = %%current
  ElsIf @Equal(%%NewState,@Get(wmppsPlaying))
    %%Panel1 = Now Playing
    #%%Panel3 = %%current
  ElsIf @Equal(%%NewState,@Get(wmppsScanForward))
    %%Panel1 = Fast Forward
    #%%Panel3 = %%current
  ElsIf @Equal(%%NewState,@Get(wmppsScanReverse))
    %%Panel1 = Reverse
    #%%Panel3 = %%current
  ElsIf @Equal(%%NewState,@Get(wmppsBuffering))
    %%Panel1 = Please wait
    %%current = buffering content...
    #%%Panel3 = buffering content
  ElsIf @Equal(%%NewState,@Get(wmppsWaiting))
    %%Panel1 = Please wait
    %%current = waiting...
    #%%Panel3 = waiting...
  ElsIf @Equal(%%NewState,@Get(wmppsMediaEnded))
    %%Panel1 = Ended
    #%%Panel3 = %%current
  ElsIf @Equal(%%NewState,@Get(wmppsTransitioning))
    %%Panel1 = Changing content...
    #%%Panel3 = changing
  ElsIf @Equal(%%NewState,@Get(wmppsReady))
    %%Panel1 = Ready...
    #%%Panel3 = Play something cool
  ElsIf @Equal(%%NewState,@Get(wmppsReconnecting))
    %%Panel1 = Reconnecting...
    #%%Panel3 = Reconnecting
  ElsIf @Equal(%%NewState,@Get(wmppsLast))
    %%Panel1 = Last...
    #%%Panel3 = %%current
	Ole Call,WMP,"Controls.play"
  ElsIf @Equal(%%NewState,@Get(wmppsUndefined))
    %%Panel1 = Undefined state
    %%current =
    #%%Panel3 = %%NewState
  End
goto evloop

:CLOSE
  If @Get(MyPlayList)
    Ole Free,Object,MyPlayList
  End
  If @Get(MyMedia)
    Ole Free,Object,MyMedia
  End
  If @Get(WMP)
    Ole DisConnectEvents,WMP,WMPOCXEvents,%%token
    Ole Call,WMP,close
    Ole Remove,WMP,%%winclass
    Ole Free,Object,WMP
  End
  Ole UnInit
Stop
:ONERROR
  %%GadgetError = @GetLastError()
  If %%GadgetError
    While %%GadgetError
      Warn %%GadgetError
      %%GadgetError = @GetLastError()
    Wend
  Else
    Warn Error @ERROR(E) at line @Succ(@ERROR(N))
  End
Goto Evloop
:End of VDSWmp