1616
1717
1818class Player (QMediaPlayer ):
19+ play_task = None
20+
1921 signal_player_media_changed = pyqtSignal ([SongModel ])
22+ signal_player_song_changed = pyqtSignal ([SongModel ])
2023 signal_playlist_is_empty = pyqtSignal ()
2124 signal_playback_mode_changed = pyqtSignal ([PlaybackMode ])
2225 signal_playlist_finished = pyqtSignal ()
@@ -25,6 +28,7 @@ class Player(QMediaPlayer):
2528 finished = pyqtSignal ()
2629
2730 _music_list = list () # 里面的对象是music_model
31+ # FIXME: _current_index is unneeded
2832 _current_index = None
2933 current_song = None
3034 _tmp_fix_next_song = None
@@ -105,12 +109,19 @@ def remove_music(self, mid):
105109 for i , music_model in enumerate (self ._music_list ):
106110 if mid == music_model .mid :
107111 self ._music_list .pop (i )
108- if self ._current_index is not None :
109- if i == self ._current_index :
110- self .play_next ()
111- elif i < self ._current_index :
112- self ._current_index -= 1
112+ if self ._current_index is None :
113113 return True
114+ if i == self ._current_index :
115+ self ._current_index = self .get_next_song_index ()
116+ if self ._current_index is None :
117+ self .current_song = None
118+ else :
119+ self .current_song = \
120+ self ._music_list [self ._current_index ]
121+ self .stop ()
122+ elif i < self ._current_index :
123+ self ._current_index -= 1
124+ return True
114125 return False
115126
116127 def get_media_content_from_model (self , music_model ):
@@ -150,22 +161,23 @@ def _play(self, music_model):
150161 and self .state () == QMediaPlayer .PlayingState :
151162 return True
152163 super ().stop ()
164+
165+ self ._current_index = index
166+ self .current_song = music_model
167+ self .signal_player_song_changed .emit (self .current_song )
168+
169+ # FIXME: cotinuously switch song may cause error and performance\
170+ # problem
153171 media_content = self .get_media_content_from_model (music_model )
154172 if media_content is not None :
155- self ._app .message ('正在准备播放 %s' % music_model .title )
156173 logger .debug ('start to play song: %d, %s, %s' %
157174 (music_model .mid , music_model .title , music_model .url ))
158- self ._current_index = index
159- self .current_song = music_model
160175 self .setMedia (media_content )
161- # super().play()
162- return True
163176 else :
164177 self ._app .message ('%s 不能播放, 准备播放下一首'
165178 % music_model .title )
166179 self .remove_music (music_model .mid )
167180 self .play_next ()
168- return False
169181
170182 def other_mode_play (self , music_model ):
171183 self ._play (music_model )
@@ -174,9 +186,10 @@ def play(self, music_model=None):
174186 if music_model is None :
175187 super ().play ()
176188 return False
177- self ._app .message ('准备播放 %s' % music_model .title )
178189 self ._app .player_mode_manager .exit_to_normal ()
190+ print ('\033 [0;31m] called 1 %s\033 [0m]' % music_model .title )
179191 self ._play (music_model )
192+ print ('\033 [0;31m] called 2 %s\033 [0m]' % music_model .title )
180193
181194 def get_index_by_model (self , music_model ):
182195 for i , music in enumerate (self ._music_list ):
0 commit comments