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()
  pinMode(led1, OUTPUT);
  pinMode(led2, OUTPUT);
  pinMode(pirInput, INPUT);
  myDFPlayer.volume(30);  //Set volume value. From 0 to 30;  //Play the first mp3

void loop()
  // Check if someone appears
  if(digitalRead(pirInput) == HIGH)
    while(digitalRead(pirInput) == HIGH) // avoid early retrigger

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);
  // 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));

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).