I have created a custom plugin to list Mp3 files from a directory in a table but I am facing an issue Joomla gives me error: 0 Class "Factory" not found
I am using Joomla 5.2.3 and PHP 8.2 on a Linux server
Here is error log:
2025-01-27T10:39:44+00:00 CRITICAL xxx.xx.xxx.xx error Uncaught Throwable of type Error thrown with message "Class "Factory" not found". Stack trace: #0 [ROOT]/plugins/content/mp3streaming/mp3streaming.php(29): PlgContentMp3StreamingHelper::getTracksFromFolder('media/mp3/New...')
#1 [ROOT]/libraries/src/Plugin/CMSPlugin.php(289): PlgContentMp3Streaming->onContentPrepare('com_content.art...', Object(stdClass), Object(JoomlaRegistryRegistry), 0)
#2 [ROOT]/libraries/vendor/joomla/event/src/Dispatcher.php(454):
Here is mp3streaming.php:
<?php
defined('_JEXEC') or die;
use JoomlaCMSPluginCMSPlugin;
use JoomlaCMSFactory;
use JoomlaCMSRouterRoute;
// Load the helper file
require_once __DIR__ . '/helper.php';
class PlgContentMp3Streaming extends CMSPlugin
{
protected $autoloadLanguage = true;
public function onContentPrepare($context, &$article, &$params, $limitstart)
{
// Regex to match the shortcode
$regex = '/{mp3streamings+artist="([^"]+)"(?:s+album="([^"]+)")?}/';
if (preg_match($regex, $article->text, $matches)) {
$artist = $matches[1];
$album = isset($matches[2]) ? $matches[2] : null;
$folderPath = 'media/mp3/' . $artist;
if ($album) {
$folderPath .= '/' . $album;
}
// Fetch and display tracks
$tracks = PlgContentMp3StreamingHelper::getTracksFromFolder($folderPath);
$html = '<div class="mp3-streaming">';
$html .= '<h3>Artist: ' . htmlspecialchars($artist) . '</h3>';
if ($album) {
$html .= '<h4>Album: ' . htmlspecialchars($album) . '</h4>';
}
$html .= '<table class="table table-striped table-hover">';
$html .= '<thead><tr>
<th>Title</th>
<th>Player</th>
<th>Download</th>
<th>Plays</th>
<th>Downloads</th>
</tr></thead><tbody>';
foreach ($tracks as $track) {
$playUrl = Route::_('index.php?option=com_ajax&plugin=mp3streaming&format=raw&task=play&id=' . $track->id);
$downloadUrl = Route::_('index.php?option=com_ajax&plugin=mp3streaming&format=raw&task=download&id=' . $track->id);
$html .= '<tr>
<td>' . htmlspecialchars($track->title) . '</td>
<td>
<audio controls preload="none" onplay="fetch('' . $playUrl . '')">
<source src="' . JUri::root() . $folderPath . '/' . $track->filename . '" type="audio/mpeg">
</audio>
</td>
<td>
<a href="' . $downloadUrl . '" class="btn btn-success btn-sm" download>Download</a>
</td>
<td>' . $track->play_count . '</td>
<td>' . $track->download_count . '</td>
</tr>';
}
$html .= '</tbody></table></div>';
$article->text = preg_replace($regex, $html, $article->text);
}
}
}
What I am missing here?
Anyone can please guide me as I am new in PHP and Joomla.