A former Bucks County youth basketball coach was sentenced to two decades in federal prison Monday for surreptitiously filming three underage members of his team showering while on an out-of-town tournament trip.

One of the teens, a 16-year-old boy, discovered a USB device equipped with a hidden camera that James Hardcastle, 42, of Bensalem, had plugged into an outlet in the bathroom of their Wildwood hotel.

But by that time, he and two others on the 2016 trip had already showered in the bathroom, which prosecutors said was not equipped with a shower curtain. The teen later saw the USB drive in his coach’s duffel bag, stole it, and handed it over to Philadelphia police last year.

Facing U.S. District Judge Gerald J. Pappert at his sentencing hearing Monday, Hardcastle expressed shame and embarrassment over his actions.

“The serious nature of these charges is fully accepted by Mr. Hardcastle as well as his responsibility for the unlawful conduct,” his attorney, Fortunato N. Perri Jr., said in court papers.

But despite Hardcastle’s contrition in court and his decision to plead guilty to counts of attempted production of child pornography and transporting minors across state lines to engage in sexual activity, Assistant U.S. Attorney Michelle Morgan noted that he initially denied his involvement when confronted by investigators last year.

Hardcastle’s “crimes … are abhorrent, outrageous, and disturbing,” she wrote in a filing submitted in advance of the sentencing. “The defendant was in a position of trust, took advantage of … teenage boys’ vulnerability in order to exploit them in a most egregious manner for his own sexual gratification.”

Prosecutors did not say Monday which youth basketball league Hardcastle was volunteering with at the time he committed his crimes. On his LinkedIn page, he identifies himself as a volunteer coach with the Liberty Bell Youth Organization. But a person who answered the phone at the league office Monday said that Hardcastle had moved on to a different league a few months before the Wildwood trip described by authorities.

After finding videos of the three boys on the USB drive, police served a search warrant on Hardcastle’s home in July 2019. He told them at the time that the USB wasn’t his, though he later admitted he had purchased it at a “spy shop” shortly before leaving on the 2016 trip.

Investigators also discovered evidence that he had installed hidden cameras in a lamp and an alarm clock in his basement, where he often let members of his team stay the night. The bathroom there, like the one in the hotel, did not have a shower curtain.

According to court filings, Hardcastle, who was working as a State Farm insurance salesman at the time, also told police he had been tipped off to their investigation shortly before they arrived to search his home. Prosecutors say he destroyed his old cell phone before they showed up and rented a storage unit in which investigators discovered crates containing packages of boys’ underwear.

In court Monday, Perri, Hardcastle’s lawyer, submitted an evaluation done by a forensic psychologist who concluded that Hardcastle had undiagnosed depression and anxiety, and that his focus on children stemmed from self-loathing over the fact that he was gay.

Morgan scoffed at that argument, calling it offensive and a claim that “single-handedly sets the gay rights movement back decades.”

Pappert appeared to agree. The punishment he imposed Monday, which also included 20 years of probation upon Hardcastle’s release and a $75,000 fine, was five years more than that sought by the defense — a term of 15 years, in line with the mandatory minimum sentence for his crimes.

But no matter what torment Hardcastle might have been facing, his team members told the judge that the effect of his actions on them has been enduring.

In a letter, the now 20-year-old man who originally found the hidden camera said his stomach dropped when he first made the discovery in the hotel bathroom four years ago.

“All those times together, you betrayed me,” he wrote. “You used basketball as a way to attack children.”

He added: “Nothing is the same. Nothing will ever be the same.”