Results 1 to 10 of 10

Thread: [VB6] - Class MP3 player from memory.

  1. #1

    Thread Starter
    PowerPoster
    Join Date
    Feb 2015
    Posts
    2,671

    [VB6] - Class MP3 player from memory.

    Hello everyone.
    I've developed a class for asynchronous playback of MP3 files in memory. For example, this can be useful for playing background music from resources, or play from the network avoiding writing in the file. You can play multiple files at once, but some playback settings (volume, pan) for all players will be shared. This class is designed so that correctly handles the situation stop environment by buttons "Stop", "Pause" and exit on the End-statement. By tags: processed correctly only ID3v1 and ID3v2 tags, other tags are not recognized and the file is not likely to be played.

    Methods:
    • Initialize - initialize the player, the first parameter is a pointer to an MP3 file. The second parameter specifies the size of the data. The third parameter specifies whether you want to copy the file into an internal buffer inside the object and play the file from there;
    • Play - starts playing, the parameter "looped" when first playing determines whether the file is played circularly;
    • Pause - pauses playback, playback will start following the current position;
    • StopPlaying - stops playback;
    • SetPositionMs - sets the current playback position (ms);
    • GetPositionMs - returns the current playback position (ms);
    • GetDurationMs - returns the length of the file in milliseconds;
    • GetBitrate - returns the bitrate at the time of playback (kbps);
    • IsPlaying - determines whether a file is played;

    Properties:
    • Volume - sets / returns the current playback volume (0 ... 1);
    • Pan - sets / returns the current panorama playback ((left channel) -1 ... 1 (right channel)).
    Attached Files Attached Files

  2. #2

  3. #3
    Junior Member
    Join Date
    Apr 2015
    Posts
    19

    Re: [VB6] - Class MP3 player from memory.

    Hi.Tnx is very Best
    But
    Why Is Isplayed.How do I disable????????

  4. #4

  5. #5
    Junior Member
    Join Date
    Apr 2015
    Posts
    19

    Re: [VB6] - Class MP3 player from memory.

    Oh I found

    obj.Play False

    Tnx

  6. #6
    PowerPoster
    Join Date
    Jan 2020
    Posts
    3,742

    Re: [VB6] - Class MP3 player from memory.

    Public Declare Function PlaySound Lib "winmm.dll" _
      Alias "PlaySoundA" (ByVallpszName As String, _
      ByValhModule As Long, ByValdwFlags As Long) _
      As Long
    this api play wav in memory.
    before one year,i use "winmm.dll" play mp3 file,hook read file,openfile,then read from memory. the file can be empty,only for check。it's virtual file。

  7. #7
    The Idiot
    Join Date
    Dec 2014
    Posts
    2,721

    Re: [VB6] - Class MP3 player from memory.

    Im trying to implement this and I notice that waveOutSetVolume is very slow.
    I have 49 sounds that I initialize when starting the game, those sounds can be played at any time so I keep all sounds in the "buffer()" in memory.
    when I want to change the sound volume I need to loop all 49 sounds so I call:

    waveOutSetVolume Sounds(i).hWave, volume

    and it will freeze the game for around 1 second.
    the sounds are small, all together 2MB in size.

    otherwise it work well. the sounds play well.

    anything that can be done to improve speed?

    also: https://learn.microsoft.com/en-us/wi...veoutsetvolume
    Remarks
    If a device identifier is used, then the result of the waveOutSetVolume call applies to all instances of the device.
    If a device handle is used, then the result applies only to the instance of the device referenced by the device handle.

    but using device handler it will affect "all" sounds.

    also I noticed something
    if I use

    waveOutSetVolume -1, volume

    it will change the volume for everything. so it doesn't matter what I use in wDeviceID
    Last edited by baka; Apr 25th, 2023 at 05:48 AM.

  8. #8

  9. #9
    PowerPoster
    Join Date
    Jan 2020
    Posts
    3,742

    Re: [VB6] - Class MP3 player from memory.

    If you play only one or two volumes at the same time.

    There is absolutely no need to create 50 memory MP3 objects.If you only have two music objects, maybe it won't stutter if you set the volume.

    Because this memory object uses a large number of subclassed messages.

    If you need to lower the volume slowly. Then switch to a new music. You can set up three objects at most. The third object is used to load new music resources. In fact, you can also put all the music in a memory object. Each music can set the starting address of the memory variable, and the length of the byte will correspond to the length of the music.

  10. #10
    PowerPoster
    Join Date
    Jan 2020
    Posts
    3,742

    Re: [VB6] - Class MP3 player from memory.

    It may be possible to create a memory object that does not require any event subclassing.You only need two functions, one is to play music, and the other is to set the volume.

Tags for this Thread

Posting Permissions

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



Click Here to Expand Forum to Full Width