mflint;223187 Wrote:
> Regarding my incorrect use of the "split" function, could this be the
> reason why shuffled playlists appear to work OK, but I couldn't
> understand why?!
>
> If so, is there a recommended way to allow shuffled Dynamic Playlists?The
> tracks will be played in the order you return them from the
getNextDynamicPlayListTracks function.
The split could probably have caused a lot of strange things to happen,
but I'm not sure if it's related to shuffle.
If you want shuffled tracks, I think I would change the query to
something like (note the order_by directive):
Code:
--------------------
my @tracks = Slim::Schema->resultset('Track')->search( { 'contributor.id' =>
{ 'in' => [EMAIL PROTECTED] } },
{ 'join' => [ 'album', { 'contributorTracks' => 'contributor' } ] } , {
'order_by' => \'RAND()' });
--------------------
And then also change the split to (note the 0 instead of $offset):
Code:
--------------------
@tracks = splice(@tracks,0,$limit);
--------------------
I'm not sure which order the query will return the result without the
'order_by' directive. If it returns an ordered result you will need to
use the $offset in the splice command as you have it now, else it will
return the same tracks every time and only the first 10 matching tracks
will be played.
If you want to be able to play the playlists in both random and non
random order you need to return the tracks differently in these modes.
I can see two possibilities to select which mode to play a playlist
in:
1.
You can change your code so getDynamicPlayLists method return two
instances of each playlist and set a parameter differently in each of
these instances. For example:
Code:
--------------------
my %playlist = (
'id' => $playlistID,
'random' => 0,
'name' => $playlistName,
'url' => 'plugins/ArtistPlaylist/artistplaylist.html?playlistID=' .
$playlistID,
);
$result{'artistplaylist_'.$playlistID} = \%playlist;
my %playlistrandom = (
'id' => $playlistID,
'random' => 1,
'name' => $playlistName." (random)",
'url' => 'plugins/ArtistPlaylist/artistplaylist.html?playlistID=' .
$playlistID,
);
$result{'artistplaylist_random_'.$playlistID} = \%playlistrandom;
--------------------
You can then in the getNextDynamicPlayList track have something like
this:
Code:
--------------------
my $random = $playlist->{'random'};
if($random) {
# Some code to query for tracks in random order
}else {
# Some code to query for tracks in non random order
}
--------------------
2.
You can specify parameters on the playlist, this way when the user hits
play on a playlist he will be asked for the parameters. To use this you
can in getDynamicPlayList have something like this:
Code:
--------------------
my %parameter = (
'id' => 1,
'type' => 'list',
'name' => 'Choose play order',
'definition' => '1:Random,0:Ordered'
);
my %parameters = (
1 => \%parameter
);
my %playlist = (
'id' => $playlistID,
'name' => $playlistName,
'url' => 'plugins/ArtistPlaylist/artistplaylist.html?playlistID=' .
$playlistID,
'parameters' => \%parameters,
);
$result{'artistplaylist_'.$playlistID} = \%playlist;
--------------------
And in the getNextDynamicPlayListTracks you would have something like
this:
Code:
--------------------
if($parameters->{1}->{'value'} eq '1') {
# Some code to query for tracks in random order
}else {
# Some code to query for tracks in non random order
}
--------------------
A tip when debugging is that you add something like this just before
the return in getNextDynamicPlayListTracks, this way you can better see
what it returns.
Code:
--------------------
$::d_plugins && msg("Returning tracks ".Dumper([EMAIL PROTECTED])."\n");
--------------------
--
erland
Erland Isaksson
'My homepage' (http://erland.homeip.net) 'My download page'
(http://erland.homeip.net/download)
(Developer of 'TrackStat, SQLPlayList, DynamicPlayList, Custom Browse,
Custom Scan, Custom Skip, Multi Library and RandomPlayList plugins'
(http://wiki.erland.homeip.net/index.php/Category:SlimServer))
------------------------------------------------------------------------
erland's Profile: http://forums.slimdevices.com/member.php?userid=3124
View this thread: http://forums.slimdevices.com/showthread.php?t=37867
_______________________________________________
plugins mailing list
[email protected]
http://lists.slimdevices.com/lists/listinfo/plugins