Page 1 of 1

How about crossfade or beatmixing?

PostPosted: Sat Feb 18, 2012 9:52 pm
by diffy
Could Subsonic support crossfading between tracks or even beatmixing?

Re: How about crossfade or beatmixing?

PostPosted: Sun Feb 19, 2012 6:46 am
by ytechie
diffy, I think I can do crossfading using javascript, but it needs to be thought out. I currently fade my music down when a video is played. (It happens automatically using javascript.) If I think it through, I might post it!

Hope that eventually this helps ;)

Re: How about crossfade or beatmixing?

PostPosted: Sun Feb 19, 2012 12:17 pm
by BKKKPewsey
Well this I must see :D
If you can do a proper crossfade with only 1 player instance available this would produce true gapless playback.
The Holy Grail!!!!
I wait in anticipation :mrgreen:

Re: How about crossfade or beatmixing?

PostPosted: Sun Feb 19, 2012 10:24 pm
by ytechie
As I'm thinking about it, I realize that I might be able to get it to fade out and back in, but crossfading might be challenging to accomplish using one player. Still turning it over in my head though. :)

Re: How about crossfade or beatmixing?

PostPosted: Sun Feb 19, 2012 10:32 pm
by ytechie
OK. Due to the nature of the flash player, I don't think it is possible to crossfade using javascript. It is possible to fade out the last few seconds of a song and fade in the next. Sorry. Trust me, if I find a way to crossfade, there will be a tutorial on how to do it right here!

Re: How about crossfade or beatmixing?

PostPosted: Thu Jun 14, 2012 8:10 am
by elinoras
Hello ytechie,
you said you're able to fade out the last few seconds of a song and fade in the next.
How do I do that automatically to all playlist?

Many thanks.

Fade music for video playback

PostPosted: Tue Jun 19, 2012 12:37 pm
by ytechie
This is how to fade out the audio in Subsonic when a video is played.

First we will edit playlist.jsp.

Add these to the variables in the script section:

Code: Select all
var playing = 0;
var volume = 100;
var mute = 0;


Also, add the following to the flashvars in createPlayer():

Code: Select all
volume:"100",
mute:"false"

Make sure to add a comma after each variable except the last.

To track if the music is playing, change the stateListener() function like so:

Code: Select all
function stateListener(obj) { // IDLE, BUFFERING, PLAYING, PAUSED, COMPLETED
   if (obj.newstate == "COMPLETED") {
      playing = 0;
      onNext(repeatEnabled);
   } else if (obj.newstate == "PLAYING") {
      playing = 1;
   } else if (obj.newstate == "PAUSED") {
      playing = 0;
   } else if (obj.newstate == "IDLE") {
      playing = 0;
   }
}


Now we have to add two functions to track volume and mute states:

Code: Select all
function volumeListener(obj) {
   volume = obj.percentage;
}
   
function muteListener(obj) {
   if (obj.state) {
      mute = 1;
   } else {
      mute = 0;
   }
}


Now we have to add the controllers to the playerReady() function by adding these two lines:

Code: Select all
player.addControllerListener("VOLUME", "volumeListener");
player.addControllerListener("MUTE", "muteListener");


so the playerReady() function should look like this:

Code: Select all
function playerReady(thePlayer) {
   player = $("player1");
   player.addModelListener("STATE", "stateListener");      
   player.addControllerListener("VOLUME", "volumeListener");
   player.addControllerListener("MUTE", "muteListener");
   getPlaylist();
}


Now we add the pauseNow() function:

Code: Select all
function pauseNow() {
   if (playing == 1) {
      if (mute == 1) {
         player.sendEvent("PLAY","false");
      } else {
         for (var i = volume; i > 0; i--) {
            player.sendEvent("VOLUME",i);
         }
         player.sendEvent("PLAY","false");
         player.sendEvent("VOLUME",volume);
      }
   }
}


Now we have to call the pauseNow() function when a video is played.
We are going to edit playAddDownload.jsp.

We are going to add "onclick="top.playlist.pauseNow()"" to the ${videoUrl} link:
When finished, it should look like this:

Code: Select all
<c:when test="${param.video}">
   <sub:url value="/videoPlayer.view" var="videoUrl">
      <sub:param name="path" value="${param.path}"/>
   </sub:url>
   <a href="${videoUrl}" target="main" onclick="top.playlist.pauseNow()">
      <img src="<spring:theme code="playImage"/>" alt="<fmt:message key="common.play"/>" title="<fmt:message key="common.play"/>"></a>
</c:when>


That's it! Now when you play a video, any non-muted music will fade out and pause, the video will begin playing, and then the music's volume will be restored.

Note: To use this modification on Subsonic 4.7, just replace "playlist" with "playQueue" where appropriate.

Hope this helps!
:D

Re: How about crossfade or beatmixing?

PostPosted: Tue Oct 30, 2012 3:34 pm
by ninjapuffin
I would definitely vote for that addition of a crossfade option

Re: How about crossfade or beatmixing?

PostPosted: Thu Jan 17, 2013 11:04 pm
by Munger
ytechie wrote:OK. Due to the nature of the flash player, I don't think it is possible to crossfade using javascript. It is possible to fade out the last few seconds of a song and fade in the next. Sorry. Trust me, if I find a way to crossfade, there will be a tutorial on how to do it right here!


It is possible to do it with SoundManager, but really tricky - http://wheelsofsteel.net/

I have managed to implement streaming audio with crossfading in a very crude test harness, but it all goes to hell in a hand basket when the user decides to skip tracks during the crossfade period. If anyone does manage to figure it out, then please remember to provide an option not to crossfade consecutive tracks on the same album.