Twenty years after he became a viral sensation with his “American Idol” audition, William Hung is opening up about his gambling problem.

Hung shot to fame after a “so bad is it good” performance of Ricky Martin’s hit “She Bang” in 2004 as he attempted to get on the reality competition singing show.

Now, he is telling People magazine that he developed a gambling addiction.

“I quit my job three years ago and became a professional poker player,” he told the publication. “I’d been doing it on the side for a while, and I decided maybe I was good enough to go for it. I was earning way more doing that than I was at my regular job. It was going well for a while.”

Until it wasn’t.

Hung said, “Unfortunately I developed a gambling addiction.”

“I knew I was good at poker, but then I got greedy. I got into sports betting. The whole gamut. I know better (now). I wasn’t supposed to do those things, but I did it anyway,” he said. “And I paid for it. I got divorced, and I learned I had to be smart about which risks I chose to take.”

His upbeat attitude in the face of the “American Idol” judges rejection made him a favorite among viewers. Hung dropped out of college, pursued a music career, appeared on some TV shows and recorded some albums.

Eventually, Hung said, life returned to normal. He later finished his degree and landed a gig as a data analyst in the Los Angeles Sheriff’s Department.

His love of numbers helped fuel his gambling, for which he’s now in recovery.

Hung said he’s doing better these days. He’s remarried and has gone back to his day job.

“There’s nothing wrong with having a steady job after fame,” he said. “I think it’s the right thing to do, to provide for my family now.”