In a music video shot just weeks before his death, rapper XXXTentacion attended his own funeral and appeared to confront controversial allegations of abuse against him.

XXXTentacion, whose real name is Jahseh Dwayne Onfroy, was killed during an armed robbery in Miami earlier this month. The intro to his latest music video for the song Sad! shows the rapper walking up to a casket and looking inside to see his own body.

Throughout the nearly six-minute video, XXXTentacion appears to be haunted by the Grim Reaper as he reflects on his troubled past, which includes numerous accusations of violence, crime and abuse towards women.

Near the end of the video, a handwritten note from the rapper reads: “People change. Things change. And so do I.”

“As long as the outcome is good for myself and family, I'm not complaining,” the note continues. ”And I want her love all to myself. Loyalty."

The music video was posted to XXXTentacion’s YouTube channel on Thursday night, and has already surpassed over 30 million views.

A private funeral for the rapper was also held on Thursday afternoon, which was attended by several notable guests including musician Erykah Badu.

“Long live XXX,” Ms Badu wrote in an Instagram post dedicated to the rapper.

“May your mother, family, child's mother, and true fans find moments of peace.”

XXXTentacion frequently faced accusations of crime and abuse, repeatedly being arrested for robberies and battery.

He spent a period of his life in a juvenile detention centre over a gun possession charge, where he met the rapper Ski Mask the Slump God, who he’d later go on to collaborate with on multiple projects.

Authorities have arrested 22-year-old Dedrick Devonshay Williams and charged him with first degree murder in the rapper’s death.