August 06, 2020, 02:47:05 pm

News:

Own IWBasic 2.x ? -----> Get your free upgrade to 3.x now.........


PLAYMIDI$

Started by ckoehn, July 02, 2020, 12:15:17 pm

Previous topic - Next topic

0 Members and 1 Guest are viewing this topic.

ckoehn

PLAYMIDI$ command no longer seems to work on my Windows 10.  Has anyone else had a problem with this?  How did you fix it?

I also had a customer complain that when they moved my program to a new Window 10 the PLAYWAVE command didn't work.

Later,
Clint

Egil

Hi Clint,

Experienced the same problems here a while ago. But found that an old file from the IBasic Pro code Archive has a workaround that works fine.

Good Luck!
Egil

Code Select
' mediaplayer.iwb

' an example of using Windows MCI to play and control all sorts of media.
' created by Andrew
' http://www.pyxia.com/community/viewtopic.php?t=9856
' Compile as a WINDOWS target

' Needs Fletchie's ctl.lib (http://fletchie.pyxia.com/) as well as the API's from his site

DECLARE IMPORT, mciSendStringA(lpszCommand:STRING,lpszReturnString:POINTER,cchReturn:INT,hwndCallback:UINT),int
$include "ctl.inc"

DEF filename:STRING
DEF filter:STRING
DEF command,status:STRING
DEF fltTime:FLOAT
DEF min,sec,flag,i:INT

DEF w1:window
OPENWINDOW w1,0,0,350,200,@MINBOX,0,"Jukebox",&mainwindow
CONTROL w1,@BUTTON,"Play",20,120,100,20,0x50018001,11
CONTROL w1,@BUTTON,"Pause",125,120,100,20,0x50018001,12
CONTROL w1,@BUTTON,"Stop",230,120,100,20,0x50018001,13

BEGINMENU w1
  MENUTITLE "&File"
  MENUITEM "&Load Multimedia",0,1
  MENUITEM "&Play",0,4
  MENUITEM "&Stop Playback",0,3
  MENUITEM "&Quit",0,2
ENDMENU

conSliderControl(w1,10,15,100,320,16,"AF")
conSliderSetThumbSize(w1,10,12)


filter = "All files|*.*|Windows Media (*.wmv)|*.wmv|MPeg Video (*.mpg)|*.mpg|AVI Video (*.avi)|*.avi|MP3 files (*.mp3)|*.mp3|Midi files (*.mid)|*.mid|Wave Audio (*.wav)|*.wav||"
run = 1
WAITUNTIL run=0

command = "close mymidi"
mciSendStringA(command,NULL,0,0)
CLOSEWINDOW w1
END

SUB mainwindow(),INT
select @class
  CASE @IDCLOSEWINDOW
      run = 0
  CASE @IDMENUPICK
      SELECT @MENUNUM
        CASE 1
            filename = FILEREQUEST("Open media file",w1,1,filter)
            if(len(filename))
              SETCURSOR w1,@CSWAIT
              command = "close mymidi"
              mciSendStringA(command,NULL,0,0)
              command = "open \"" + filename + "\" alias mymidi"
              mciSendStringA(command,NULL,0,0)
              command = "set mymidi time format ms"
              mciSendStringA(command,NULL,0,0)
              flag=1
              'Strip the filename from the path
              for i=1 to len(filename)
                  if mid$(filename,i,1)="\\" then flag=i
              next i
              move w1,10,10
              print w1,right$(filename,len(filename)-flag)
              command = "info mymidi product"
              mciSendStringA(command,status,254,0)
              move w1,10,30
              print w1,status + " - " + right$(filename,3)+" file"
              command = "status mymidi length"
              mciSendStringA(command,status,254,0)
              status = left$(status,8)
              conSliderSetRange(w1,10,0,int(val(status)/1000))
              status=MStoTime(status)
              move w1,10,50
              print w1,"Length: ",status
              starttimer w1,200
              SETCURSOR w1,@CSARROW
            endif
        CASE 3
            command = "stop mymidi"
            mciSendStringA(command,NULL,0,0)
        CASE 4
            command = "play mymidi"
            mciSendStringA(command,NULL,0,0)
        CASE 2
            run = 0
      ENDSELECT
  CASE @IDTIMER
      command = "status mymidi position"
      mciSendStringA(command,status,254,0)
      status = left$(status,8)
      conSliderSetPos(w1,10,int(val(status)/1000))
      status=MStoTime(status)
      MOVE w1,10,70
      PRINT w1,"  Time: ",status
  CASE @IDCONTROL
      SELECT @CONTROLID
        CASE 11: 'Play
            command = "play mymidi"
            mciSendStringA(command,NULL,0,0)
        CASE 12: 'Pause
            command = "stop mymidi"
            mciSendStringA(command,NULL,0,0)
        CASE 13: 'Stop
            command = "stop mymidi"
            mciSendStringA(command,NULL,0,0)
            command = "seek mymidi to start"
            mciSendStringA(command,NULL,0,0)
            conSliderSetPos(w1,10,0)
      ENDSELECT
  CASE @IDHSCROLL
      'Seek
      min=conSliderGetPos(w1,10)
      command= "seek mymidi to "+str$(min*1000)
      mciSendStringA(command,NULL,0,0)
      command="play mymidi"
      mciSendStringA(command,NULL,0,0)
  CASE @IDCREATE
      CENTERWINDOW w1
ENDSELECT
RETURN 0
ENDSUB

Sub MStoTime(ins as string),string
  'Converts milliseconds to readable time format mm:ss
  string retval,strSec
  fltTime=val(ins)
  fltTime/=1000
  fltTime/=60
  min=int(fltTime)
  sec=int((fltTime-min)*100)
  strSec=ltrim$(str$(sec))
  retval=ltrim$(str$(min))+":"
  if len(strSec)=1 then retval=retval+"0"
  retval=retval+strSec
  return retval
EndSub


Support Amateur Radio  -  Have a ham  for dinner!

ckoehn

July 02, 2020, 07:07:45 pm #2 Last Edit: July 02, 2020, 07:20:19 pm by ckoehn
Thanks a bunch.  Will try.  Glad to see you are still around. Andy was wondering if something had happened to you.  :)

I did a quick look and it looks like that will play a MID file,  but can it play something like PLAYMIDI$ "T180 N0 I0 O5 C8C#DD#EFF#GG#AA#B O6 CC#DD#EFF#GG#AA#B O7 C1" like the help example shows?

Egil

Quote from: ckoehn on July 02, 2020, 07:07:45 pmI did a quick look and it looks like that will play a MID file,  but can it play something like PLAYMIDI$ "T180 N0 I0 O5 C8C#DD#EFF#GG#AA#B O6 CC#DD#EFF#GG#AA#B O7 C1" like the help example shows?

Sorry Clint, my knowledge of MIDI is next to nothing, so unable to help you with that particular question. But I remember seeing code for making MIDI files, produced with commands like that. So maybe it should be possible to save the commands as a MIDI file in memory and play it with the routines from the example??


Good luck!
Egil
Support Amateur Radio  -  Have a ham  for dinner!

ckoehn

Here is another cool win api call (requires "windowssdk.inc"):

mciSendString("play AlarmSound.wav",NULL,0,NULL)

mciSendString("stop AlarmSound.wav",NULL,0,NULL)

mciSendString("status AlarmSound.wav ready",NULL,0,NULL))

mciSendString("close AlarmSound.wav",NULL,0,NULL)

It will also play .mid files.

There are other "commands" that you can send to access the Multimedia control interface.  Just check for mciSendString and mciSendCommand.

This still didn't help my problem.  Groove music will play the wav file but IWBasic won't.  I have no idea what the problem is. It works on other computers but not that one.  That one is a laptop but it is using Realtek Audio just like mine.

Later,
Clint