[Slim-Checkins] r10083 - /branches/6.5/server/Plugins/Rhapsody/ProtocolHandler.pm

andy at svn.slimdevices.com andy at svn.slimdevices.com
Thu Sep 28 07:55:35 PDT 2006


Author: andy
Date: Thu Sep 28 07:55:33 2006
New Revision: 10083

URL: http://svn.slimdevices.com?rev=10083&view=rev
Log:
Rework Rhapsody Radio title handling to use newsong callback.  Force repeat mode during radio play.

Modified:
    branches/6.5/server/Plugins/Rhapsody/ProtocolHandler.pm

Modified: branches/6.5/server/Plugins/Rhapsody/ProtocolHandler.pm
URL: http://svn.slimdevices.com/branches/6.5/server/Plugins/Rhapsody/ProtocolHandler.pm?rev=10083&r1=10082&r2=10083&view=diff
==============================================================================
--- branches/6.5/server/Plugins/Rhapsody/ProtocolHandler.pm (original)
+++ branches/6.5/server/Plugins/Rhapsody/ProtocolHandler.pm Thu Sep 28 07:55:33 2006
@@ -34,8 +34,17 @@
 	
 	$url = _verifyPort( $url );
 	
+	if ( $url =~ /\.rhr$/ ) {
+		# Watch for playlist commands for radio mode
+		Slim::Control::Request::subscribe( 
+			\&playlistCallback, 
+			[['playlist'], ['repeat', 'newsong']],
+		);
+		return $url;
+	}
+	
 	# Direct stream supported for audio files but not playlists
-	return $url if $url =~ /(?:rhr|wma)$/;
+	return $url if $url =~ /\.wma$/;
 
 	return;
 }
@@ -96,8 +105,6 @@
 		
 		if ( my $trackURL = $radioTracks{ $client->id }->{$rhapURL} ) {
 			
-			delete $radioTracks{ $client->id }->{$rhapURL};
-			
 			# direct stream the audio file
 			$url = $trackURL;
 			
@@ -305,22 +312,7 @@
 		for my $everybuddy ( $client, Slim::Player::Sync::syncedWith($client) ) {
 			$radioTracks{ $everybuddy->id }->{$url} = $trackURL;
 		}
-		
-		# Set title on a timer so it doesn't appear too early
-		my $elapsed  = $client->songElapsedSeconds;
-		my $tracklen = 
-			( $client->currentsongqueue->[-1] ) 
-			? $client->currentsongqueue->[-1]->{'duration'}
-			: $client->currentsongqueue->[0]->{'duration'};
-			
-		my $showIn = $tracklen - $elapsed;
-		my $showAt = time + ( $showIn || 0 );
-		
-		Slim::Utils::Timers::setTimer( $client, $showAt, sub {
-			my $client = shift;
-			Slim::Music::Info::setCurrentTitle( $url, Slim::Music::Info::standardTitle($client, $tracks[0]) );
-		} );
-		
+
 		# change the format of this URL back to wma so $client->stream doesn't think it's m3u
 		Slim::Music::Info::setContentType( $url, 'wma' );
 		
@@ -328,6 +320,42 @@
 	}
 
 	return @tracks;
+}
+
+sub playlistCallback {
+	my $request = shift;
+	my $client  = $request->client();
+	my $p1      = $request->getRequest(1);
+	
+	return unless defined $client;
+	
+	# check that user is still using Rhapsody Radio
+	my $url = Slim::Player::Playlist::url($client);
+	
+	if ( !$url || $url !~ /\.rhr$/ ) {
+		# stop listening for playback eventss
+		Slim::Control::Request::unsubscribe( \&playlistCallback );
+		return;
+	}
+	
+	# The user has changed the repeat setting.  Radio requires a repeat
+	# setting of '2' (repeat all) to work properly
+	if ( $p1 eq 'repeat' ) {
+		$::d_plugins && msg("Rhapsody: Radio mode, user changed repeat setting, forcing back to 2\n");
+		
+		Slim::Player::Playlist::repeat( $client, 2 );
+		
+		if ( $client->playmode =~ /playout/ ) {
+			$client->playmode( 'playout-play' );
+		}
+	}
+	elsif ( $p1 eq 'newsong' ) {
+		# A new song has started playing.  We use this to change titles
+		my $trackURL = delete $radioTracks{ $client->id }->{$url};
+		my $title    = Slim::Music::Info::standardTitle( $client, $trackURL );
+		
+		Slim::Music::Info::setCurrentTitle( $url, $title );
+	}
 }
 
 sub canDoAction {



More information about the checkins mailing list