PyQt5 で python-vlc を扱う

PyQt5==5.15.0
PyQt5-sip==12.8.0
python-vlc==3.0.11115

Pythonスクリプト

import os
os.chdir(os.path.join(os.getcwd(), 'sound'))

import vlc
import time

import sys
from PyQt5 import QtCore, QtSerialPort
from PyQt5.QtWidgets import *
from PyQt5.QtGui import QImage, QPixmap

ql_x_position = (200, 400, 600, 200, 400, 600, 200, 400, 600)
qr_x_position = (1160, 1360, 1560, 1160, 1360, 1560, 1160, 1360, 1560)
q_y_position = (80, 80, 80, 280, 280, 280, 480, 480, 480)
a_x_position = (25, 215, 405, 595, 785, 975, 1165, 1355, 1545, 1735)
a_y_position = (700, 890)

player = vlc.MediaListPlayer()
mediaList = vlc.MediaList(['dummy.wav'])
player.set_media_list(mediaList)
player.play()

class Window(QWidget):

    def __init__(self):
        super().__init__()
        self.initUI()
        self.question = True
        self.serial = QtSerialPort.QSerialPort(
            'COM5', baudRate=QtSerialPort.QSerialPort.Baud9600, 
            readyRead = self.receive)
        self.serial.open(QtCore.QIODevice.ReadWrite)
        time.sleep(1.5)

    def initUI(self):

        self.label_list_left = [QLabel(self) for i in range(9)]
        self.label_list_right = [QLabel(self) for i in range(9)]
        
        for i in range(9):
            self.label_list_left[i].setGeometry(QtCore.QRect(ql_x_position[i], q_y_position[i], 160, 160))
        
        for i in range(9):
            self.label_list_right[i].setGeometry(QtCore.QRect(qr_x_position[i], q_y_position[i], 160, 160))

        self.label_list_2 = [QLabel(self) for i in range(10)]
        self.label_list_3 = [QLabel(self) for i in range(10)]

        for i in range(10):
            self.label_list_2[i].setGeometry(QtCore.QRect(a_x_position[i], a_y_position[0], 160, 160))

        for i in range(10):
            self.label_list_3[i].setGeometry(QtCore.QRect(a_x_position[i], a_y_position[1], 160, 160))

    def receive(self):

        dummy = self.serial.readAll()

        if self.question == True:
            
            # 画像の表示
            for i in range(9):
                self.label_list_left[i].setPixmap(QPixmap.fromImage(image))
                self.label_list_right[i].setPixmap(QPixmap.fromImage(image))

            for i in range(10):
                self.label_list_2[i].setPixmap(QPixmap.fromImage(image))
                self.label_list_3[i].setPixmap(QPixmap.fromImage(image))

            self.question = False

            mediaList = vlc.MediaList(['2.wav'])
            player.set_media_list(mediaList)
            player.play()

        else:

            mediaList = vlc.MediaList(['1.wav'])
            player.set_media_list(mediaList)
            player.play()

            # 画像の消去
            for i in range(9):
                self.label_list_left[i].clear()
                self.label_list_right[i].clear()

            for i in range(10):
                self.label_list_2[i].clear()
                self.label_list_3[i].clear()
                
            self.question = True

    def keyPressEvent(self, e):

        # エスケープキーを押すと画面が閉じる
        if e.key() == QtCore.Qt.Key_Escape:
            self.close()

image = QImage('donut.png').scaled(160,160,QtCore.Qt.KeepAspectRatio) 

app = QApplication(sys.argv)
ex =Window()

ex.showFullScreen()
sys.exit(app.exec_())