what if I had a never ending mp3 file that I was streaming from a radio station... in DRUPAL 7.
It seems that you want to upload an MP3 file and play that...
any alternative ideas?

Comments

tripper54’s picture

I'm trying to do something similar - I want to use jplayer to play back an mp3 stream from a shoutcast server. Does anyone have an idea of the code I could embed in a static page to do this?

granttoth’s picture

I'm no coder but I want to think that someone could use the existing code but modify it to use a text field input rather than the file field.

digitalfrontiersmedia’s picture

Would this be as simple as changing the field types listed in the jplayer_field_formatter_info function of the jplayer.module file?

jaylivid’s picture

Version: 7.x-2.x-dev » 6.x-1.0-beta3

This was my solution in Drupal 6

View you page source code in Firefox to confirm on a page already containing a player if you have one running using a file you upload.

I had to add these lines into the theme page.tpl
as the module automatically appends this to the head when a player is present, but will not do so if you manually add the code to a block or page.

<link type="text/css" rel="stylesheet" media="all" href="/modules/j/jplayer/theme/jplayer.css?i" />
<script src="/sites/all/libraries/jplayer/jquery.jplayer.min.js?i"></script>
<script src="/modules/j/jplayer/theme/jplayer.js?i"></script>
<script>
<!--//--><![CDATA[//><!--
jQuery.extend(Drupal.settings, {"jPlayer": { "swfPath": "/sites/all/libraries/jplayer", "autoPlay": 0 }});
//--><!]]>

Then this code in a block or page.
Works 100% and also does not clash with other instances of the player as long as the identifying number isn't the same (148) you could up or down that number. it is uniquely assigned.

Just add your stream url into the section marked.

<div id="jplayer-148-field-chartaudio-0" class="jplayer" rel="XXXXXX YOUR STREAM URRL XXXXXX"></div>
<div class="jp-single-player">
  <div class="jp-interface">
    <ul class="jp-controls">
      <li><a href="#" id="jplayer-148-field-chartaudio-0-play" class="jp-play" title="play">play</a></li>
      <li><a href="#" id="jplayer-148-field-chartaudio-0-pause" class="jp-pause" title="pause">pause</a></li>
      <li><a href="#" id="jplayer-148-field-chartaudio-0-stop"class="jp-stop" title="stop">stop</a></li>
</ul>
    <div id="jplayer-148-field-chartaudio-0-progress" class="jp-progress" title="progress">
      <div id="jplayer-148-field-chartaudio-0-load-bar" class="jp-load-bar">
        <div id="jplayer-148-field-chartaudio-0-play-bar" class="jp-play-bar"></div>
      </div>
    </div>
    <div id="" class="" title="">
      <div id="" class=""></div>
    </div>
    <div id="jplayer-148-field-chartaudio-0-play-time" class="jp-play-time"></div>
    <div id="jplayer-148-field-chartaudio-0-total-time" class="jp-total-time"></div>
  </div><div id="jplayer-148-field-chartaudio-0-playlist" class="jp-playlist"></div></div>
joemoraca’s picture

I just spend a few hours trying to get jplayer to work with a shoutcast stream with not very good results. It is working great with file uploads and urls that point to mp3 files but I just can't get it to work with a shoutcast stream.

I was using http://jsfiddle.net/75lb/FBNZa/ -- so I know jplayer can do this. Is there no way to make this work using the drupal 7 module?

Even more annoying .... other feeds work fine in the jsfiddle code but not mine ;-( -- is there something in the shoutcast admin that needs to be changed.

http://67.228.150.184:7770 ;listen.pls (wslr.org - a low power FM station)

I really like JPlayer !!

digitalfrontiersmedia’s picture

Hi Joe,

I think even the Drupal 7 version allows you to template the player so you should be able to write it to include the stream info correctly.

I just looked and was able to easily get your jsfiddle to play SLR's stream ( http://jsfiddle.net/FBNZa/149/ ). In SLR's case, it looks like you don't need to even bother with the stream mounting point. So you may have merely had a typo in there causing a syntax error.

digitalfrontiersmedia’s picture

I should note that SLR's stream played fine for me in Mac Safari 5.1.1. I've noticed that some implementations of the jPlayer in certain conditions doesn't setup the fallback correctly so you may experience problems due to the codec licensing issues with certain browsers. Try switching up browsers when trying out your jsfiddle code trying to play the WSLR stream.

joemoraca’s picture

Yes it seems very "finicky" - it doesn't work for me in either chrome or firefox on ubuntu - yet other streams with the same code work.

deviantintegral’s picture

Version: 6.x-1.0-beta3 » 7.x-2.x-dev

jPlayer as-is is pretty heavily tied to local files. I don't see any patches here, but I'd envision it as building on something like Link just as we use the file field type with a display formatter. There would need to be some pretty heavy refactoring of the code for the display formatter, but it's doable.

jtolj’s picture

Status: Active » Needs review
StatusFileSize
new1.23 KB

Here's a quick patch to add support for using jPlayer as a field formatter for a link_field. This is working fine for me on an Icecast stream, with an extension of .mp3. Something more complex would be required to support Shoutcast or arbitrary stream URLs.

There are some memory issues when using the flash solution, which is best solved by reloading the stream at some interval (I usually do one hour). Would be good if that functionality was handled in the module js as well.

Aside: in Icecast, if your stream url doesn't already end in .mp3 or .ogg (not tested) you can use the alias setting in icecast.xml
<alias source="/foo" dest="/bar.mp3"/>

mostou’s picture

Great work jtolj!

Instead of using the icecast setting in icecast.xml serverside, another possibility is to set the stream type/extension when filling out the url for the stream. One way of doing that could be via the 'title' Attribute for the link. A use-case scenario would be when you don't have access to the icecast.xml file.

A slightly modified patch is attached. If title-attribute is filled out, and if file extension cannot be found in the multimedia-arrays, it will look for the extension in the link 'title' Attribute.

I have read http://www.w3.org/TR/WCAG10-HTML-TECHS/#links and in my oppinion it is a valid use of the title-attribute. Any comments for this approach?

tripper54’s picture

Patch in #11 works great for me. Thanks!

chegor’s picture

I tried to apply this patch and now there are some errors:
Notice: Undefined index: extension in jplayer_sort_files() (line 127 of \sites\all\modules\jplayer\includes\jplayer.theme.inc).
Notice: Undefined index: type in jplayer_sort_files() (line 176 of \sites\all\modules\jplayer\includes\jplayer.theme.inc).
Notice: Undefined index: type in jplayer_sort_files() (line 182 of \sites\all\modules\jplayer\includes\jplayer.theme.inc).

And it does not work with mp3 stream.

mostou’s picture

What version of the module are you using? Are you using a link-field? Did you try to clear the cache? Please elaborate some more about your settings.

chegor’s picture

I tried with 7.x-2.0-beta1 and after your question - with last dev. And yes. I'm using link field. I aded "mp3" as title for URL and got the same result (errors) as if use only url without title. Clearing the cache does not work.
Also, fyi I work with this url - http://94.25.53.133/nashe-192

1st error is here:
else {
$item['ext'] = $fileinfo['extension'];

2nd:
if (isset($file) && $file['type'] == 'audio') {
$files[][$file['ext']] = $file['url'];
$extensions[] = $file['ext'];
$playlist[] = l($file['label'], $file['url'], array('attributes' => array('id' => $player_id . '_item_' . $num, 'tabindex' => 1)));
$num++;
}

3-rd:
elseif (isset($file) && $file['type'] == 'video') {
$files[][$file['ext']] = $file['url'];
if ($poster != NULL) {
$files[]['poster'] = $poster;
}

mostou’s picture

When I test with your URL the stream works. Remember to use the "Link title attribute" and not the "Title" for the extension "mp3".

However I also receive some error messages with your url:
Notice: Undefined index: extension in jplayer_sort_files() (line 123 of /network/web/xfm.dk/sites/all/modules/jplayer/includes/jplayer.theme.inc).
Notice: Undefined index: extension in jplayer_sort_files() (line 123 of /network/web/xfm.dk/sites/all/modules/jplayer/includes/jplayer.theme.inc).
Notice: Undefined index: extension in jplayer_sort_files() (line 123 of /network/web/xfm.dk/sites/all/modules/jplayer/includes/jplayer.theme.inc).

mostou’s picture

I can reproduce the following two errors:
Notice: Undefined index: type in jplayer_sort_files() (line 176 of \sites\all\modules\jplayer\includes\jplayer.theme.inc).
Notice: Undefined index: type in jplayer_sort_files() (line 182 of \sites\all\modules\jplayer\includes\jplayer.theme.inc).

These are due to the use of "Title" instead of "Link title attribute" for the extension "mp3".

mostou’s picture

The other error is because $fileinfo['extension'] is returning null - in your case because of no '.' in your url after the basedir. The patch needs to be updated so it handles the cases where $fileinfo['extension'] returns null. I don't know when I have time to update the patch - I will try and see if I have time next week - otherwise anyone else is welcome to take a look.

Btw if you test out with my url you will see it is working:
http://stream.xfm.dk:8000

This is because $fileinfo['extension'] in this case returns ".dk:8000". So hopefully updating the patch will get rid of your errors.

mostou’s picture

Rerolled patch to latest dev version resulted in a more compact patch. Apparently some other patches have tidied up the code for the use of link-field.

Remember to use the "Link title attribute" for this patch to work. Chegor - let me know if this works for you.

chegor’s picture

Aha! #19 works. Thank you so much for your help!

radiobuzzer’s picture

Hi, the patch made the jplayer available, but my stream doesn't play. I am trying to figure out why. It is a shoutcast stream and its URL is of the kind: http://myserver.com:8000 . Any help would be appreciated. I have specified mp3 in the title of the link, as well as the title attribute of the Link field

EDIT: I managed to make the stream of the other user play (in the previous post) but still not mine. Funnily enough, if one specifies mp3 in both the Link title and the a title attribute, the player doesn't start. If I change tha Link title to "my radio", it works!

EDIT 2: I also managed to make my Shoutcast stream play. The problem is that the Shoutcast URL is ambiguous, depending on what MIME type the player asks for. You can open a Shoutcast url with a web browser, which would give you the status pager, whereas a player would receive the MP3 stream, out of the same URL.

The solution is to explicity ask for the raw stream file, by appending /;stream/1 to the url, so that it becomes http://myserver.com:8000/;stream/1 . This would cause a validation error, so in order to get this through, one needs to edit the Link field and disable the URL validation.

Conclusion: the patch works, please commit it to the upstream. At some point, one should think about a "Stream" field, which would provide more options (such as the stream type, or an option to add the shoutcast extension).

tripper54’s picture

Issue summary: View changes
Status: Needs review » Reviewed & tested by the community

Setting to RTBC based on my experiences and comments above.

markie’s picture

Status: Reviewed & tested by the community » Postponed (maintainer needs more info)

Can someone tell me if the latest dev build fixes this issue? The patches are pretty old (my fault)

lquessenberry’s picture

Bump for commit to module. I too am looking for a way to use jPlayer for streams in Drupal rather than uploading files, I'd like to use link or something like that.

lquessenberry’s picture

I see that there is an ability to play something in jPlayer from a link, but I would really like to play PLS and M3U files the same way.

lquessenberry’s picture

I tried manually writing the patch changes into the file to be patched but it still doesn't work. I am trying to use a stream with mp3 extension. Should I try ;stream/1 instead of ;stream.mp3 ?

markie’s picture

@lquessenberry: can you add a patch here so I can check out the work you've done?

mostou’s picture

@markie: as far as I can see from the latest dev version it is not fixed. I am currently on vacation but will as soon as possible update the patch from #19 to the latest dev version and of course test to ensure the patch still works.

@lquessenberry: did you use the "link title attribute" for the file extension? What is the full link for your stream?

mostou’s picture

Status: Postponed (maintainer needs more info) » Needs review
StatusFileSize
new1.12 KB

Patch rerolled to latest dev version. Same changes were required. Tested and works in my use case scenario.

lquessenberry’s picture

http://pub1.strobe.fm/192 (icecast stream)

lquessenberry’s picture

http://media01.lynx.evehost.net:8032/;stream.mp3 (Shoutcast MP3)
http://tunein.streamguys1.com/cnn (Not sure what kind of stream)

All of the streams are working with plain tags in HTML5, but I did not know about a link title attribute as mentioned.

mostou’s picture

@lquessenberry: I have tested your streams:
http://pub1.strobe.fm/192
OK - remember to enter mp3 in the link title attribute

http://media01.lynx.evehost.net:8032/;stream.mp3
OK - you do not need to enter mp3 in the link title attribute in this scenario since the url ends with the mp3 extension

http://tunein.streamguys1.com/cnn
Remember to enter mp3 in the link title attribute. Prompts for an Icecast login - cannot test further.

Please read #11 on how to use this patch. For a specific link field you can enable the "Link title" option under Structure -> Content Types -> your content type -> Manage fields. And then on the specific node you can enter "mp3" in the Link Title Attribute if the stream url does not end with the extension ".mp3". Please test the patch again with this in mind and let me know if you experience any issues. If everything works please change the status of this issue to "Reviewed and tested by the community". Thank you.

lquessenberry’s picture

Thanks @motsou. I have reinstalled the latest dev. Should I be able to patch that with no problems? Also, I have trouble patching sometimes. Is there any way one of you could post a patched version of the files I can use and test with? I will gladly confirm the status of tested by the community if I can get my patches to work. ;)

lquessenberry’s picture

Warning: file_get_contents(): Filename cannot be empty in jplayer_get_version() (line 311 of /srv/bindings/63b1317c286441fab6fcd00c10d363bb/code/sites/all/modules/jplayer/jplayer.module).
Notice: Undefined index: data in drupal_process_attached() (line 4537 of /srv/bindings/63b1317c286441fab6fcd00c10d363bb/code/includes/common.inc).
Warning: file_get_contents(): Filename cannot be empty in jplayer_get_version() (line 311 of /srv/bindings/63b1317c286441fab6fcd00c10d363bb/code/sites/all/modules/jplayer/jplayer.module).
Notice: Undefined index: data in drupal_process_attached() (line 4537 of /srv/bindings/63b1317c286441fab6fcd00c10d363bb/code/includes/common.inc).
Notice: Undefined offset: 0 in __lambda_func() (line 3 of /srv/bindings/63b1317c286441fab6fcd00c10d363bb/code/sites/all/modules/views_php/plugins/views/views_php_handler_field.inc(202) : runtime-created function).

This is what I am getting when using the title attribute 'mp3'

lquessenberry’s picture

lquessenberry’s picture

http://puu.sh/eBIuh/6c645ca0d2.png This is what my field looks like. Is there something I need to do in display settings?

lquessenberry’s picture

I am getting the same error on all of the streams. Something about Filename can not be empty.

lquessenberry’s picture

Okay, I am an idiot. The patch works great. My problem was that I misconfigured my sites/all/libraries folder for the player. It said jPlayer instead of all lowercase jplayer. i can confirm this is working and congratulate you all on a job well done. Thank you thank you thank you!

lquessenberry’s picture

Status: Needs review » Reviewed & tested by the community

Is working great for me now.

  • markie committed 460ab1f on 7.x-2.x authored by mostou
    Issue #1276078 by mostou, jtolj: streaming a radio mp3
    
markie’s picture

Status: Reviewed & tested by the community » Fixed

Patch has been added to the 7.x-2.x branch. Should show up in the dev build within 12 hours. Thanks for your help.

Status: Fixed » Closed (fixed)

Automatically closed - issue fixed for 2 weeks with no activity.

westside85’s picture

Hi

Thanks for the patch! On the official site of jPlayer writes that the player supports and works with .ogg (Vorbis/Theora).
Can it be made to work and here?

Ddroid_za’s picture

Hi Thanks for all the info here, helped me a lot. I also want to know if .m3u8 extensions will work?