mp3 file stops playing

mp3 file stops playing

by Tim Allen -
Number of replies: 12
Hi fellow moodlers,

Yesterday I uploaded a 4.6 MB mp3 music file as a resource ("link to a file or website"). However, when I play it using the flash plug-in control panel, it stops playing after 1:21 seconds, even thought it is less than half over. sad

When I move this file to my web server document root and go to it in my browser, it opens up in a quicktime plug-in in IE and plays the whole song. But when it is within the moodle data folder, it doesn't seem to play properly. Neither the mp3 text filter nor the mp3 resource plug-in play right the way through. Even when I click on a HTML link and play it in Windows Media Player it stops after 41% is downloaded and played and gives a network error. Finally, if I right-click and save it to my computer and then play it from there, again it only plays 1:23 seconds.

Is this a problem with PHP or Moodle? Any tips or advice about how I can solve or troubleshoot this problem? It is very strange..

TIA,
Tim. smile
Average of ratings: -
In reply to Tim Allen

Re: mp3 file stops playing

by Timothy Takemoto -
I have had the same problem, but I thought it was just me. One of my sound files (no where near as big) only plays for about half its length. I thought it was somethign really simple but I did not get to the bottom of it and have not had time to try. I guess the first thing to do would be to post the relevant sounds files here?
Timothy
In reply to Timothy Takemoto

Re: mp3 file stops playing

by Tim Allen -
Thanks for the reply Timothy.

I don't think it is related to a file, because I just tried another file of a similar size and the same thing happened. This file plays fine from my server document root,  but inside Moodle files always finish after 1:23 seconds! sad

Maybe this is a server setting - but I don't know where to look. If anyone could point me in the right direction, I would really appreciate it.

Tim.
In reply to Tim Allen

Re: mp3 file stops playing

by Sean S -
Tim,

If you email the mp3 I'll upload it to my site which is on shared hosting and see if I get the same problem. If I don't then you'll at least know it is your server settings.
In reply to Sean S

Re: mp3 file stops playing - please help!

by Tim Allen -
Actually, I just tried it on my webhost and it worked perfectly, so I am now sure the problem lies in my server configuration. I have tried all the relevant settings in php.ini to no avail. sad

I am at a loss as to what the problem is - I really hope someone has an explanation for me!

Tim.
In reply to Tim Allen

Re: mp3 file stops playing

by Hiroto Kagotani -
Are you using PHP 5.0.4?
This version of PHP has a bug in its readfile function, which stops sending files at 2,000,000 bytes (see bug 3048).

I am using a hack in send_file function in lib/filelib.php, which is replacing 2 readfile function calls with:

if ($filesize <= 2000000) {
readfile($path);
} else {
$fp = fopen($path, "rb");
while (strlen($data = fread($fp, 256*1024))) {
echo $data;
}
fclose($fp);
}

Hope this helps.
Average of ratings: Useful (1)
In reply to Hiroto Kagotani

Re: mp3 file stops playing

by Tim Allen -
Thank you so much Hiroto!  big grin

Yes I am using PHP 5.0.4 and that was exactly the problem.  approve

I am using Moodle 1.4.5 and there is no filelib.php in that version.  So after googling I decided to patch PHP and recompile instead, according to the following diff:

--- php-5.0.4/main/php_streams.h.bug32553	2005-04-25 19:45:27.000000000 +0200
+++ php-5.0.4/main/php_streams.h 2005-04-25 19:46:33.000000000 +0200
@@ -413,7 +413,8 @@
* Uses mmap if the src is a plain file and at offset 0
* To ensure we don't take up too much memory when reading large files, set the default mmap length
* at this many bytes */
-#define PHP_STREAM_COPY_ALL 2000000
+// #define PHP_STREAM_COPY_ALL 2000000
+#define PHP_STREAM_COPY_ALL ((size_t)-1)

BEGIN_EXTERN_C()
PHPAPI size_t _php_stream_copy_to_stream(php_stream *src, php_stream *dest, size_t maxlen STREAMS_DC TSRMLS_DC);
(Source: https://bugzilla.redhat.com/bugzilla/show_bug.cgi?id=155916).

It is all fixed now - I just wish is was easier to find out about this serious bug in PHP.

Thanks again!  smile
In reply to Tim Allen

Re: mp3 file stops playing

by Peter Richardson -
Tim,

I am a newbie at PHP , but seem to have the same problem you did with larger mp3 files.  As a newbie, I could not understand your final post on the subject and since I used Xampp to install PHP, I am unsure how I would recompile.  I am using 5.0.4 and 1.4.5

Can you help?

Thanks.
In reply to Peter Richardson

Re: mp3 file stops playing

by Peter Richardson -
Tim,

More info.  In looking at the Xampp documentation, it looks like it would be easy to go back to php 4.3.11.  Would that solve my problem?  Do you know if it would create others?

Thanks again.

In reply to Peter Richardson

Re: mp3 file stops playing

by Tim Allen -
Hi Peter,

This bug is a problem in PHP version 5.0.4 only, so going back to version 4.3.11 would surely solve the problem, yes!  As far as I know, version 4.3.11 is stable and without bugs, so it shouldn't create other problems for you.

Tim.  smile


In reply to Peter Richardson

Re: mp3 file stops playing

by Robert Brenstein -
I just ran into the same problem: students reported problems downloading large PDF files. Luckily for me, I just read about this PHP bug here big grin

In my installation (OSX 10.3.8, PHP 5.0.4, Moodle 1.4.4+), the file to patch is

/moodle/file.php

And the actual PHP code to replace readfile() is:

  if (filesize($pathname) < 2000000) {
    readfile($pathname);
  } else {
    $fp = fopen($pathname,"rb");
    while (strlen($data = fread($fp,256*1024))) {
      echo $data;
    }
    fclose($fp);
  }


Actually, since I do not filter downloadable files, I needed to replace only the second readfile().
In reply to Peter Richardson

Re: mp3 file stops playing

by Tim Allen -
Hi Peter,

It depends a little on whether you are using XAMPP on Windows, Linux, Mac or other.

In any case, because XAMPP is a bundled package and also because it is not distributed in source code (at least not on the main downloading page), it may be difficult or impossible to fix this problem by patching the source code and then recompiling PHP.

Instead, I suggest you simply use XAMPP with version with PHP 4.3.11, as you suggest in your other post below:

By the following command you can switch "back" to PHP 4.3.x:

/opt/lampp/lampp php4
And with the following command you can switch back to PHP 5.0.x:
/opt/lampp/lampp php5
If you forgot which version of PHP is in use simply use phpinfo() or call this command:
/opt/lampp/lampp phpstatus (from http://www.apachefriends.org/en/xampp-linux.html#374)

You don't even need to reinstall, just switch PHP 4.3.11 on using the commands above. wink

Alternatively, if Moodle is the only PHP software you are running, or if you don't have shell access to your web server, you could change the code within moodle as explained by Peter (and Hiroto) . Do this in moodle/file.php for Moodle 1.4.5 or in lib/filelib.php. I haven't tried this myself but it worked for Hiroto and Peter.

If you need more help, don't hesistate to ask here and I will give more details!
HTH,
Tim. smile

In reply to Peter Richardson

Re: mp3 file stops playing

by Peter Richardson -
Robert and Tim,

Thanks so much for your help.  I tried to follow Robert's advice, but must have done it incorrectly as it did not work.  So I used the xampp command to convert to php 4 and it seems to have worked like a charm (in seconds without a lot of fuss).  I must say, I love those xampp (apachefriends.org) people.

Peter