Reputation: 201
I need to display the play duration of a video on my website.
I tried using getid3
but it's not working, it's showing warnings like:
preg_match() expects parameter 2 to be string, array given in C:\wamp\www\PE\getid3\getid3.php on line 262
Warning: is_readable() expects parameter 1 to be a valid path, array given in C:\wamp\www\PE\getid3\getid3.php on line 271
Warning: file_exists() expects parameter 1 to be a valid path, array given in C:\wamp\www\PE\getid3\getid3.php on line 271
This are the warning Etc., and the result is not showing.
Here is my code:
<?php
ini_set('display_errors',1);
ini_set('display_startup_errors',1);
ini_set('output_buffering','Off');
error_reporting(-1);
include_once("getid3/getid3.php");
$getID3 = new getID3;
$SongPath = pathinfo('http://localhost/PE/uploads/pe_discussion/videos/Wildlife.wmv');
set_time_limit(30);
$ThisFileInfo = $getID3->analyze($SongPath);
getid3_lib::CopyTagsToComments($ThisFileInfo);
echo 'File name: '.$ThisFileInfo['filenamepath'].'<br>';
echo 'Artist: '.(!empty($ThisFileInfo['comments_html']['artist'])
? implode('<BR>', $ThisFileInfo['comments_html']['artist'])
: ' ').'<br>';
echo 'Title: '.(!empty($ThisFileInfo['comments_html']['title'])
? implode('<BR>', $ThisFileInfo['comments_html']['title'])
: ' ').'<br>';
echo 'Bitrate: '.(!empty($ThisFileInfo['audio']['bitrate'])
? round($ThisFileInfo['audio']['bitrate'] / 1000).' kbps'
: ' ').'<br>';
echo 'Play time: '.(!empty($ThisFileInfo['playtime_string'])
? $ThisFileInfo['playtime_string']
: ' ').'<br>';
?>
Upvotes: 1
Views: 5867
Reputation: 31
Here is quick answer for you: The file must be downloaded first to your server.
Here is simple example:
$SongPath = 'http://localhost/PE/uploads/pe_discussion/videos/Wildlife.wmv';
if($SongPath){
$filename = tempnam('/tmp','getid3');
if (file_put_contents($filename, file_get_contents($SongPath, false, null, 0, 300000))) {
if (require_once('getid3/getid3.php')) {
$getID3 = new getID3;
$ThisFileInfo = $getID3->analyze($filename);
}
unlink($filename);
}
}
var_dump($ThisFileInfo['playtime_string']);
PS: Just replace your $SongPath with existing external url.
Upvotes: 1