MV Script calls for media controls needed.

I want to build a media player for .ogg files into an RPG maker project.
Now, there are a few things I can't figure out and I don't even know where to start looking for the right scrip call, if they even exist.

So, I will probably use ME to play the audio files. I choose this because it will not repeat the file ones the file is done playing.

I know how to play them in order, how to stop them, how to skip to the next or previous ME, without the need of separate calls for each file.

Here is what I don't know how to do:
  1. I need to know when the ME is ended, to auto play all chapters. I only need to know how to see if any ME is playing at all, I know how to do the rest..
  2. I need a way to pause the ME. Not just to stop it, but I need to be able to resume the replay wherever I stopped it. So I need codes to do one of the following two.
    (If I can do one, I don't need the other. I prefer the second option, if possible):
    • I need 2 script calls to pause and to resume the file.
    • I need 2 script calls to find how long the current file has been playing, and to start playing a file at a specific time.
If anyone could help me out, I would be forever thankful.

(Edit: Omg, how were there so many typos in this single post? Why was nothing red underlined? 😛 Spell checker is on, since ogg is underlined. 😛 )
When an ME stops playing, its buffer becomes null. E.g. this should be true iff an ME is playing:
JavaScript:
!!AudioManager._meBuffer
For other buffers, I think you can use something like:
JavaScript:
AudioManager._bgmBuffer && AudioManager._bgmBuffer.isPlaying()
AudioManager._bgsBuffer && AudioManager._bgsBuffer.isPlaying()

About pause/playback:
  1. The WebAudio API AudioContext has suspend and resume methods for this, e.g.
    JavaScript:
    WebAudio._context.suspend();
    WebAudio._context.resume();
    RMMV uses this single context for all audio, so this will affect all in-game audio simultaneously.

    (This won't work if the game uses Html5Audio instead, but in the latest version of MV's core scripts, shouldUseHtml5Audio always returns false. So no worries there.)

  2. The core scripts implement a seek method that can be used to get the current playback time for a given buffer, e.g.
    JavaScript:
    AudioManager._meBuffer.seek()
    I believe this can then be used as an offset for a buffer's play method:
    JavaScript:
    AudioManager._meBuffer.play(loop, offset);
    loop is true or false; offset is a number, e.g. the seek value.

    If you stop the ME as usual, then as mentioned, that will clear its buffer. Try playing it again (e.g. via event command), then immediately follow up with play(loop, offset) to restart it at the correct time.

    Note that seek and play are pitch-dependent, because pitch simply adjusts the playback rate.

[Edit: updated the generic "buffer is playing" check to short-circuit if the buffer is null.]
When an ME stops playing, its buffer becomes null. E.g. this should be true iff an ME is playing:
JavaScript:
!!AudioManager._meBuffer
For other buffers, I think you can use something like:
JavaScript:
AudioManager._bgmBuffer.isPlaying()

About pause/playback:
  1. The WebAudio API AudioContext has suspend and resume methods for this, e.g.
    JavaScript:
    WebAudio._context.suspend();
    WebAudio._context.resume();
    RMMV uses this single context for all audio, so this will affect all in-game audio simultaneously.

    (This won't work if the game uses Html5Audio instead, but in the latest version of MV's core scripts, shouldUseHtml5Audio always returns false. So no worries there.)

  2. The core scripts implement a seek method that can be used to get the current playback time for a given buffer, e.g.
    JavaScript:
    AudioManager._meBuffer.seek()
    I believe this can then be used as an offset for a buffer's play method:
    JavaScript:
    AudioManager._meBuffer.play(loop, offset);
    loop is true or false; offset is a number, e.g. the seek value.

    If you stop the ME as usual, then as mentioned, that will clear its buffer. Try playing it again (e.g. via event command), then immediately follow up with play(loop, offset) to restart it at the correct time.

    Note that seek and play are pitch-dependent, because pitch simply adjusts the playback rate.
Thanks!! I will try to play around with this later today. I need to experiment with those before I can actually understand them, I guess. Seems so complicated. But I am sure that I can figure it out now.

Thank you so much. Last night, when I saw the first few people watched my post, I just hoped one of them was you. Because if there would be 1 person who would know this, it would have been you. 😛
You're welcome, good luck! 👋

I realised that the BGM and BGS buffers may also be null at various points, so a safer way to check if the BGM is still playing would be something like:
JavaScript:
AudioManager._bgmBuffer && AudioManager._bgmBuffer.isPlaying()
I'll edit that into my previous post.
Thanks. I will only use ME in this project, though.

Or do you think BGM would be better for this?

The sound files are longer than most ME, but they should absolutely not loop. It is for a podcast.
By default the engine loops BGM/BGS, so I agree: ME sounds best for your case.
This is a lot more work intensive as I at first have imagined. This project needs to be shelved for a bit.

I am also working on making my card game pvp, and I already have enough trouble finding time to do that. I should have waited before I even mentioned this new idea.

Original thread: https://forums.rpgmakerweb.com/threads/script-calls-for-media-controls-needed.159994/