Use thread for fading
This commit is contained in:
parent
d0b8028f90
commit
6643da84b6
@ -2,6 +2,7 @@
|
||||
|
||||
import vlc
|
||||
import sys
|
||||
import threading
|
||||
|
||||
from datetime import datetime, timedelta
|
||||
from log import DEBUG, ERROR
|
||||
@ -15,6 +16,7 @@ from ui.dlg_search_database_ui import Ui_Dialog
|
||||
|
||||
from config import Config
|
||||
from model import Playdates, Playlists, Settings, Tracks
|
||||
from time import sleep
|
||||
|
||||
|
||||
class Music:
|
||||
@ -98,6 +100,20 @@ class Music:
|
||||
except AttributeError:
|
||||
return ""
|
||||
|
||||
def fade_current(self):
|
||||
thread = threading.Thread(target=self._fade_current)
|
||||
thread.start()
|
||||
|
||||
def _fade_current(self):
|
||||
player = self.current_track['player']
|
||||
position = player.get_position()
|
||||
for i in range(100, 0, -10):
|
||||
player.audio_set_volume(i)
|
||||
sleep(0.2)
|
||||
player.pause()
|
||||
player.audio_set_volume(100)
|
||||
player.set_position(position)
|
||||
|
||||
def play_next(self):
|
||||
if self.previous_track['player']:
|
||||
self.previous_track['player'].release()
|
||||
@ -190,9 +206,10 @@ class Window(QMainWindow, Ui_MainWindow):
|
||||
record.update({'f_int': self.y()})
|
||||
|
||||
def connectSignalsSlots(self):
|
||||
self.actionSearch_database.triggered.connect(self.selectFromDatabase)
|
||||
self.actionPlay_selected.triggered.connect(self.play_next)
|
||||
self.actionFade.triggered.connect(self.fade)
|
||||
self.actionPlay_next.triggered.connect(self.play_next)
|
||||
self.actionPlay_selected.triggered.connect(self.play_next)
|
||||
self.actionSearch_database.triggered.connect(self.selectFromDatabase)
|
||||
self.playlist.itemSelectionChanged.connect(self.set_next_track)
|
||||
self.timer.timeout.connect(self.tick)
|
||||
|
||||
@ -200,6 +217,9 @@ class Window(QMainWindow, Ui_MainWindow):
|
||||
dlg = DbDialog(self)
|
||||
dlg.exec()
|
||||
|
||||
def fade(self):
|
||||
self.music.fade_current()
|
||||
|
||||
def play_next(self):
|
||||
self.music.play_next()
|
||||
self.current_track.setText(
|
||||
|
||||
@ -596,7 +596,7 @@ border: 1px solid rgb(85, 87, 83);</string>
|
||||
<addaction name="actionSearch_database"/>
|
||||
<addaction name="actionAdd_file"/>
|
||||
<addaction name="separator"/>
|
||||
<addaction name="actionF_ade"/>
|
||||
<addaction name="actionFade"/>
|
||||
<addaction name="actionS_top"/>
|
||||
</widget>
|
||||
<addaction name="menuFile"/>
|
||||
@ -622,7 +622,7 @@ border: 1px solid rgb(85, 87, 83);</string>
|
||||
</attribute>
|
||||
<addaction name="actionPlay_selected"/>
|
||||
<addaction name="actionPlay_next"/>
|
||||
<addaction name="actionF_ade"/>
|
||||
<addaction name="actionFade"/>
|
||||
<addaction name="separator"/>
|
||||
<addaction name="actionAdd_file"/>
|
||||
<addaction name="actionSearch_database"/>
|
||||
@ -679,7 +679,7 @@ border: 1px solid rgb(85, 87, 83);</string>
|
||||
<string>Add &file</string>
|
||||
</property>
|
||||
</action>
|
||||
<action name="actionF_ade">
|
||||
<action name="actionFade">
|
||||
<property name="icon">
|
||||
<iconset>
|
||||
<normaloff>icon-fade.png</normaloff>icon-fade.png</iconset>
|
||||
|
||||
Loading…
Reference in New Issue
Block a user