none
Musicplayer FNG130 Microsoft Small Basic RRS feed

  • Question

  • In the program FNG130 are 2 errors in the sub onkeydown when press key pause or key F1. Please help me (sorry for my bad english)
    Wednesday, April 7, 2010 4:12 PM

Answers

  • This requires writing an extension to SmallBasic in a .Net language.

    Here's one I wrote (C++ in this case - I can give you the code if you want):

    http://cid-92f7df0e57232aba.skydrive.live.com/self.aspx/.Public/SmallBasic/MusicPlayTime/MusicPlayTime%20v0.8.zip

    It has to open the music file to get its data, so is a little slow to be used on a lot of files.  Only tested on my Vista PC.

    I also was playing with your music player for my own interest adding some stuff like recursively getting of music files (mp3 and wma) below the set directory.  Here it is or just use the extension (download and copy contents to the SmallBasic lib directory (C:\Program Files\Microsoft\Small Basic\lib).  Import KNV544.

    • Marked as answer by martmen Friday, April 9, 2010 1:51 PM
    Thursday, April 8, 2010 9:32 PM
    Moderator

All replies

  • A couple of things.

    1] Just set a flag in the event subroutine and use this flag to control the program in a main While ("True") .. EndWhile loop. 

    This is a general feature of SmallBasic programming and you should always try to do this - there are many recent threads showing problems, when this approach is not used.

    2] You need to use Sound.Play(LPath) , not Sound.PlayAndWait(LPath) , otherwise you cannot interrupt the play.

    Here are the relevant changes:

    GraphicsWindow.KeyDown = OnKeyDownEvent
    KeyDownEvent = 0
    Sub OnKeyDownEvent
      KeyDownEvent = 1
    EndSub

    and

    PlaySong()
    While IC >= Index
      If (KeyDownEvent = 1) Then
        OnKeyDown()
        KeyDownEvent = 0
      EndIf
      Program.Delay(100)
    EndWhile

    And

    Sound.Play(LPath)

    The whole thing is Import NHN564, modified to play some music on my PC obviously.

    EDIT - there is second Sound.PlayAndWait(LPath) that I didn't notice first time for you to change.

    Wednesday, April 7, 2010 5:48 PM
    Moderator
  • Hello litdev,

    thank you, but if you press F1 he do not play the next song.

    In the path are many mp3-files not only one.

    ' The following line could be harmful and has been automatically commented.

    'DN = File.GetFiles(Path)

    In this array are all the mp3-files and is Random = 0 he shall play all the songs. It is possible to change it?

    best regard

    Martin

    Wednesday, April 7, 2010 6:19 PM
  • Using my path which also has several songs the F1 does play the next song. Make sure the GraphicsWindow is active before pressing F1.

    The only issue remaining (for me) is that if you use the Sound.Play to allow an interrupt, then when the song finishes it doesn't automatically play the next - I don't know of any easy way to detect that the current song has finished other than using Sound.PlayAndWait and waiting for it to finish - but then you can't interrupt it.

    EDIT

    The following starts a new song (randomly or not) every 3 minutes - not perfect, but without knowing the song length this is about the best I can do, while retaining the interrupt pause, F1 features. You have to change to your path as before.  Import RMC264.  You also have to uncomment the File operations which are automatically commented during the publish.

    Wednesday, April 7, 2010 6:34 PM
    Moderator
  • To start a new song every 3 minutes is not good. It is possible in VB2010 to read the song length? The best place are to change

    DN = File.GetFiles(Path)

    with a routine to read the FileName and the lengt. Can you help me?

    Thursday, April 8, 2010 7:08 PM
  • This requires writing an extension to SmallBasic in a .Net language.

    Here's one I wrote (C++ in this case - I can give you the code if you want):

    http://cid-92f7df0e57232aba.skydrive.live.com/self.aspx/.Public/SmallBasic/MusicPlayTime/MusicPlayTime%20v0.8.zip

    It has to open the music file to get its data, so is a little slow to be used on a lot of files.  Only tested on my Vista PC.

    I also was playing with your music player for my own interest adding some stuff like recursively getting of music files (mp3 and wma) below the set directory.  Here it is or just use the extension (download and copy contents to the SmallBasic lib directory (C:\Program Files\Microsoft\Small Basic\lib).  Import KNV544.

    • Marked as answer by martmen Friday, April 9, 2010 1:51 PM
    Thursday, April 8, 2010 9:32 PM
    Moderator
  • in VB.net i believe you can use the media player object to get the file length. check this link out:

     

    http://www.daniweb.com/forums/thread273746.html#

     

    I am sure i read there is a method like getFileDuration() or something like that to get the actual time length of the file if that helps.

    • Edited by _msanders_ Thursday, April 8, 2010 10:38 PM tried my theory, won't work :(
    Thursday, April 8, 2010 9:45 PM
  • In the program FNG130 are 2 errors in the sub onkeydown when press key pause or key F1. Please help me (sorry for my bad english)

    ************************************************************************************************************

    NEW

    *************************************
    * The new Version is now in GGW510   *
    ********************************

    ***********************************************************************************************

     

    Wednesday, April 14, 2010 12:48 PM
  • Nice - good use of subroutines and events.  I think you need calls to ChangeRandomStatus() ChangePauseStatus() and set a flag (e.g. S3 = 1 and S4 = 1) etc in CheckButton in the appropriate IFs to set the button flag as pressed.  To help debug this, you could print all the flag status to a TextWindow in the main loop to see what is happening as you do it.

    Also for any other users, the extension linked to earlier in this thread is required as well as the usual un-commenting of File operation commands from the imported program.

    Wednesday, April 14, 2010 6:43 PM
    Moderator
  • Hello litdev,

    please send me c-code from MusicPlayTime. I will upgrade for a if with strings, so it works faster.

    thank yuo Martin

    Thursday, April 22, 2010 6:45 PM
  • C++ Visual Studio 2008 (not 2010 since this uses .Net 4.0, not 3.5) Express project for music file run timings at:

    http://cid-92f7df0e57232aba.skydrive.live.com/self.aspx/.Public/SmallBasic/MusicPlayTime/Music.zip

    You may need to include the SmallBasicLibrary.dll reference.  I have previously uploaded some instuctions for a similar project (C# that time).  You may want to do a new project with C# or VB; these are more natural choices for .Net, I only used C++ because I am more used to its syntax.

    http://cid-92f7df0e57232aba.skydrive.live.com/self.aspx/.Public/SmallBasic/SpeechMusic/C%5E3Instructions.zip

    Post if you have questions.

    Thursday, April 22, 2010 7:03 PM
    Moderator