Syncing LED flashes with sound file while flickering in between flashes

Beginner here. I’m following this video on youtube to pair a jack-o-lantern with flickering LEDs, a PIR sensor, and a sound file from a DFPlayer Mini module. Here is the code:

#include "Arduino.h"
#include "DFRobotDFPlayerMini.h"

// candle effect
void flicker();

DFRobotDFPlayerMini myDFPlayer;
uint8_t brightness;
int led1 = 5;
int led2 = 6;
int pirInput = 4;

void setup()
{
  Serial.begin(9600);
  pinMode(led1, OUTPUT);
  pinMode(led2, OUTPUT);
  pinMode(pirInput, INPUT);
  myDFPlayer.begin(Serial); 
  myDFPlayer.volume(30);  //Set volume value. From 0 to 30
  myDFPlayer.play(1);  //Play the first mp3
}

void loop()
{
  // Check if someone appears
  if(digitalRead(pirInput) == HIGH)
  {
    myDFPlayer.next();
    while(digitalRead(pirInput) == HIGH) // avoid early retrigger
    {
      flicker();
    }
    delay(1000);
  }
}

void flicker()
{
  // set an initial PWM value first and 
  brightness = 128;
  for(uint16_t i = 0; i < 1000; i++)
  {
    analogWrite(led1, brightness);        
    brightness += random(-20, 20);
    analogWrite(led2, brightness);        
    brightness += random(-20, 20);
    delay(10);
  }
  // finally turn off the LEDs
  analogWrite(led1, 0);
  analogWrite(led2, 0);
}

What I want to do is have the LEDs flicker on a dimmer pattern in its idle state and flash brightly when the sound file plays. Adding this:

  analogWrite(led1, 15+random(60));
  analogWrite(led2, 15+random(60));
  delay(random(40));

to the bottom of the loop section works fine for the idle flicker pattern, but how do I program the flashing sequence (with a slight flickering effect while flashing) when the PIR reads high, and also time it so it resumes the idle flicker sequence as soon as the sound file is done playing?

You could connect a wire from the BUSY pin of the DFplayer to a digital input and see if the Arduino can read it (it's a 3.3V signal, hopefully digitalRead() can read it ok).