@@ -643,6 +643,7 @@ def __init__(self, pyradio_config,
643643 self.ws.CLEAR_ALL_REGISTERS_MODE: self._print_clear_all_registers,
644644 self.ws.STATION_INFO_ERROR_MODE: self._print_station_info_error,
645645 self.ws.STATION_INFO_CHANGED_MODE: self._print_station_info_change,
646+ self.ws.PLAYING_STATION_CHANGED_ERROR_MODE: self._print_station_change_error,
646647 self.ws.STATION_INFO_MODE: self._show_station_info,
647648 self.ws.STATION_DATABASE_INFO_MODE: self._browser_station_info,
648649 self.ws.RENAME_PLAYLIST_MODE: self._show_rename_dialog,
@@ -2464,6 +2465,10 @@ def _wait_for_threads(self):
24642465
24652466 def _goto_playing_station(self, changing_playlist=False):
24662467 ''' make sure playing station is visible '''
2468+ if self._last_played_playlist != self._cnf.station_title:
2469+ if not changing_playlist:
2470+ self._print_station_change_error()
2471+ return
24672472 if (self.player.isPlaying() or self.ws.operation_mode == self.ws.PLAYLIST_MODE) and \
24682473 (self.selection != self.playing or changing_playlist):
24692474 if changing_playlist:
@@ -3632,6 +3637,12 @@ def _print_register_save_error(self):
36323637 string_to_display
36333638 )
36343639
3640+ def _print_station_change_error(self):
3641+ self._open_simple_message_by_key_and_mode(
3642+ self.ws.PLAYING_STATION_CHANGED_ERROR_MODE,
3643+ 'M_PLAYING_STATION_CHANGE_MODE'
3644+ )
3645+
36353646 def _print_station_info_change(self):
36363647 self._open_simple_message_by_key_and_mode(
36373648 self.ws.STATION_INFO_CHANGED_MODE,
@@ -3919,30 +3930,33 @@ def _align_stations_and_refresh(self,
39193930 self.startPos = 0
39203931 else:
39213932 if not force_scan_playlist and self.player.isPlaying():
3922- ''' The playlist is not empty '''
3923- if self.playing > self.number_of_items - 1 or self._cnf.is_register:
3924- ''' Previous playing station is now invalid
3925- Need to scan playlist '''
3926- need_to_scan_playlist = True
3927- else:
3928- if self.stations[self.playing][0] == self.active_stations[1][0]:
3929- ''' ok, self.playing found, just find selection '''
3930- self.selection = self._get_station_id(self.active_stations[0][0])
3931- if logger.isEnabledFor(logging.DEBUG):
3932- logger.debug('** Selected station is {0} at {1}'.format(self.stations[self.selection], self.selection))
3933+ if self._last_played_playlist == self._cnf.station_title:
3934+ ''' The playlist is not empty '''
3935+ if self.playing > self.number_of_items - 1 or self._cnf.is_register:
3936+ ''' Previous playing station is now invalid
3937+ Need to scan playlist '''
3938+ need_to_scan_playlist = True
39333939 else:
3934- ''' station playing id changed, try previous station '''
3935- self.playing -= 1
3936- if self.playing == -1:
3937- self.playing = len(self.stations) - 1
39383940 if self.stations[self.playing][0] == self.active_stations[1][0]:
39393941 ''' ok, self.playing found, just find selection '''
39403942 self.selection = self._get_station_id(self.active_stations[0][0])
39413943 if logger.isEnabledFor(logging.DEBUG):
3942- logger.debug('** Selection station is {0} at {1}'.format(self.stations[self.playing ], self.playing ))
3944+ logger.debug('** Selected station is {0} at {1}'.format(self.stations[self.selection ], self.selection ))
39433945 else:
3944- ''' self.playing still not found, have to scan playlist '''
3945- need_to_scan_playlist = True
3946+ ''' station playing id changed, try previous station '''
3947+ self.playing -= 1
3948+ if self.playing == -1:
3949+ self.playing = len(self.stations) - 1
3950+ if self.stations[self.playing][0] == self.active_stations[1][0]:
3951+ ''' ok, self.playing found, just find selection '''
3952+ self.selection = self._get_station_id(self.active_stations[0][0])
3953+ if logger.isEnabledFor(logging.DEBUG):
3954+ logger.debug('** Selection station is {0} at {1}'.format(self.stations[self.playing], self.playing))
3955+ else:
3956+ ''' self.playing still not found, have to scan playlist '''
3957+ need_to_scan_playlist = True
3958+ else:
3959+ need_to_scan_playlist = True
39463960 else:
39473961 ''' not playing, can i get a selection? '''
39483962 need_to_scan_playlist = True
@@ -3952,17 +3966,28 @@ def _align_stations_and_refresh(self,
39523966 self.detect_if_player_exited = False
39533967 if logger.isEnabledFor(logging.DEBUG):
39543968 logger.debug('Scanning playlist for stations...')
3955- # logger.error('DE \n\n{}\n\n'.format(self.active_stations))
3956- self.selection, self.playing = self._get_stations_ids((
3957- self.active_stations[0][0],
3958- self.active_stations[1][0]))
3969+ logger.error('DE \n\n{}\n\n'.format(self.active_stations))
3970+ logger.error('DE \n\n{}\n\n'.format(self._last_played_station))
3971+ logger.error('DE \n\n{}\n\n'.format(self._last_played_playlist))
3972+ if self.player.isPlaying():
3973+ if self.active_stations[1][0]:
3974+ self.selection, self.playing = self._get_stations_ids((
3975+ self.active_stations[0][0],
3976+ self.active_stations[1][0]))
3977+ logger.error('1')
3978+ else:
3979+ self.selection, self.playing = self._get_stations_ids((
3980+ self.active_stations[0][0],
3981+ self._last_played_station[0]))
3982+ logger.error('2')
3983+ else:
3984+ self.selection, self.playing = self._get_stations_ids((
3985+ self.active_stations[0][0],
3986+ self.active_stations[1][0]))
3987+ logger.error('3')
39593988 # TODO: continue playing after changing playlist
39603989 # if self.player.isPlaying():
3961- if self.playing == -1:
3962- self.stopPlayer()
3963-
3964- ''' calculate new position '''
3965- if self.player.isPlaying():
3990+ if self.playing > -1:
39663991 if logger.isEnabledFor(logging.DEBUG):
39673992 logger.debug('Setting playing station at {}'.format(self.playing))
39683993 self.setStation(self.playing)
@@ -3974,6 +3999,7 @@ def _align_stations_and_refresh(self,
39743999 self.startPos = a_startPos
39754000 else:
39764001 self.selection = 0
4002+ self.startPos = 0
39774003 if logger.isEnabledFor(logging.DEBUG):
39784004 logger.debug('Setting selection station at {}'.format(self.selection))
39794005 self.setStation(self.selection)
@@ -3985,6 +4011,11 @@ def _align_stations_and_refresh(self,
39854011 ''' make sure playing station is visible '''
39864012 if cur_mode != self.ws.REMOVE_STATION_MODE:
39874013 self._goto_playing_station(changing_playlist=True)
4014+ ''' make sure playing station is visible '''
4015+ if self.selection < 0:
4016+ ''' make sure we have a valid selection '''
4017+ self.selection = 0
4018+ self.startPos = 0
39884019
39894020 if logger.isEnabledFor(logging.DEBUG):
39904021 logger.debug('self.selection = {0}, self.playing = {1}, self.startPos = {2}'.format(self.selection, self.playing, self.startPos))
@@ -4090,7 +4121,7 @@ def _show_recording_status_in_header(
40904121 if self.player.buffering:
40914122 b_header = 'B'
40924123 elif self._last_played_station and \
4093- self.stations[self.selection][ Station.buffering][0] != '0':
4124+ not self._last_played_station[ Station.buffering].startswith( '0') :
40944125 b_header = 'b'
40954126
40964127 ''' v for station volume and P for station profile disabled '''
@@ -4627,6 +4658,7 @@ def _get_station_id(self, find):
46274658 return -1
46284659
46294660 def _get_stations_ids(self, find):
4661+ logger.error('\n\nfind = "{}"\n\n'.format(find))
46304662 ch = -2
46314663 i_find = [-1, -1]
46324664 debug_str = ('selection', 'playing')
@@ -4667,7 +4699,8 @@ def _set_active_stations(self):
46674699 if self.player.isPlaying():
46684700 self.active_stations = [
46694701 [self.stations[self.selection][0], self.selection],
4670- [self.stations[self.playing][0], self.playing]
4702+ # an empty name (also playing=-1), says no playback, or playlist change
4703+ ['' if self.playing == -1 else self.stations[self.playing][0], self.playing]
46714704 ]
46724705 else:
46734706 if self.number_of_items > 0:
@@ -4685,7 +4718,8 @@ def _set_rename_stations(self):
46854718 if self.player.isPlaying():
46864719 self.rename_stations = [
46874720 [self.stations[self.selection][0], self.selection],
4688- [self.stations[self.playing][0], self.playing]
4721+ # an empty name (also playing=-1), says no playback, or playlist change
4722+ ['' if self.playing == -1 else self.stations[self.playing][0], self.playing]
46894723 ]
46904724 else:
46914725 if self.number_of_items > 0:
@@ -4868,6 +4902,9 @@ def _show_station_info(self):
48684902
48694903 logger.error(f'{self.player._icy_data = }')
48704904
4905+ # if playlist has changed, do not offer rename
4906+ if self._last_played_playlist != self._cnf.station_title:
4907+ tail = ''
48714908 msg = txt + tail
48724909 #logger.error('msg\n{}'.format(msg))
48734910 if tail and not self._cnf.browsing_station_service:
@@ -5625,10 +5662,11 @@ def _handle_passive_windows(self):
56255662
56265663 def _normal_station_info(self):
56275664 if self.player.isPlaying():
5628- if self._last_played_playlist == self._cnf.station_title:
5629- self._show_station_info()
5630- else:
5631- self._print_station_info_change()
5665+ self._show_station_info()
5666+ # if self._last_played_playlist == self._cnf.station_title:
5667+ # self._show_station_info()
5668+ # else:
5669+ # self._print_station_info_change()
56325670 else:
56335671 self._print_station_info_error()
56345672
0 commit comments