Example #1
0
class Finestra(QMainWindow):
    def __init__(self, master=None):
        QMainWindow.__init__(self, master)
        self.title = 'Video'
        self.width = 640
        self.height = 480
        vlcInstance = vlc.Instance()
        self.player = vlcInstance.media_player_new()
        media = vlcInstance.media_new_path(path)
        self.player.set_media(media)
        self.initUI()

    def initUI(self):
        self.setWindowTitle(self.title)
        self.widget = QWidget(self)
        self.setCentralWidget(self.widget)

        self.videoframe = QMacCocoaViewContainer(0)
        self.palette = self.videoframe.palette()
        self.palette.setColor(QPalette.Window, QColor(0, 0, 0))
        self.videoframe.setPalette(self.palette)
        self.videoframe.setAutoFillBackground(True)

        self.vboxlayout = QVBoxLayout()
        self.vboxlayout.addWidget(self.videoframe)
        self.widget.setLayout(self.vboxlayout)
        self.player.set_nsobject(int(self.videoframe.winId()))
        self.play()

    def play(self):
        self.resize(self.width, self.height)
        self.show()
        self.player.play()
    def createUI(self):
        """Set up the user interface, signals & slots
        """
        self.widget = QWidget(self)
        self.setCentralWidget(self.widget)
        self.widget.setStyleSheet("background: '#EEEEEE';")

        image_path = os.getcwd() + "/mamaro/babybedPNG/login0.png"
        image_profile = QtGui.QImage(image_path)  #QImage object

        lbl1 = QtWidgets.QLabel('bluetoothstate', self)
        lbl1.setObjectName('bluetoothstate')
        lbl1.setPixmap(QtGui.QPixmap.fromImage(image_profile))
        lbl1.setScaledContents(True)
        lbl1.setGeometry(48, 38, 195, 120)
        lbl1.resize(lbl1.sizeHint())

        #create background
        lbl1 = QtWidgets.QLabel('back1', self)
        lbl1.setObjectName('back1')
        lbl1.setText("")
        lbl1.setFont(QtGui.QFont("ms gothic", 28))
        lbl1.setStyleSheet("background: 'white';")
        lbl1.setGeometry(0, 120, 297, 296)

        lbl1 = QtWidgets.QLabel('back2', self)
        lbl1.setObjectName('back2')
        lbl1.setText("")
        lbl1.setFont(QtGui.QFont("ms gothic", 28))
        lbl1.setStyleSheet("background: 'white';")
        lbl1.setGeometry(0, 420, 297, 296)

        lbl1 = QtWidgets.QLabel('back3', self)
        lbl1.setObjectName('back3')
        lbl1.setText("")
        lbl1.setFont(QtGui.QFont("ms gothic", 28))
        lbl1.setStyleSheet("background: 'white';")
        lbl1.setGeometry(0, 720, 297, 296)
        #create background

        #create icon
        image_path = os.getcwd() + "/mamaro/babybedPNG/height0.png"
        image_profile = QtGui.QImage(image_path)  #QImage object

        lbl1 = QtWidgets.QLabel('heighticon', self)
        lbl1.setObjectName('heighticon')
        lbl1.setPixmap(QtGui.QPixmap.fromImage(image_profile))
        lbl1.setScaledContents(True)
        lbl1.setStyleSheet("background: 'white';")
        lbl1.setGeometry(91, 180, 115, 104)

        image_path = os.getcwd() + "/mamaro/babybedPNG/weight0.png"
        image_profile = QtGui.QImage(image_path)  #QImage object

        lbl1 = QtWidgets.QLabel('weighticon', self)
        lbl1.setObjectName('weighticon')
        lbl1.setPixmap(QtGui.QPixmap.fromImage(image_profile))
        lbl1.setScaledContents(True)
        lbl1.setStyleSheet("background: 'white';")
        lbl1.setGeometry(91, 480, 115, 104)

        image_path = os.getcwd() + "/mamaro/babybedPNG/temp0.png"
        image_profile = QtGui.QImage(image_path)  #QImage object

        lbl1 = QtWidgets.QLabel('tempicon', self)
        lbl1.setObjectName('tempicon')
        lbl1.setPixmap(QtGui.QPixmap.fromImage(image_profile))
        lbl1.setScaledContents(True)
        lbl1.setStyleSheet("background: 'white';")
        lbl1.setGeometry(91, 780, 115, 104)
        # lbl1.resize(lbl1.sizeHint());

        #create text
        lbl1 = None

        lbl1 = QtWidgets.QLabel('heighttext', self)
        lbl1.setObjectName('heighttext')
        lbl1.setText("")
        lbl1.setFont(QtGui.QFont("ms gothic", 28))
        lbl1.setStyleSheet("color:#9EA2A2;")
        #lbl1.setAlignment(QtCore.Qt.AlignTop)
        lbl1.setAlignment(QtCore.Qt.AlignCenter)
        lbl1.setGeometry(91, 314, 115, 46)

        lbl1 = QtWidgets.QLabel('weighttext', self)
        lbl1.setObjectName('weighttext')
        lbl1.setText("")
        lbl1.setFont(QtGui.QFont("ms gothic", 28))
        lbl1.setStyleSheet("color:#9EA2A2;")
        #lbl1.setAlignment(QtCore.Qt.AlignTop)
        lbl1.setAlignment(QtCore.Qt.AlignCenter)
        lbl1.setGeometry(91, 614, 115, 52)

        lbl1 = QtWidgets.QLabel('temptext', self)
        lbl1.setObjectName('temptext')
        lbl1.setText("")
        lbl1.setFont(QtGui.QFont("ms gothic", 28))
        lbl1.setStyleSheet("color:#9EA2A2;")
        #lbl1.setAlignment(QtCore.Qt.AlignTop)
        lbl1.setAlignment(QtCore.Qt.AlignCenter)
        lbl1.setGeometry(91, 914, 115, 46)

        lbl1 = QtWidgets.QLabel('contentcover', self)
        lbl1.setObjectName('contentcover')
        lbl1.setText("")
        lbl1.setCursor(Qt.PointingHandCursor)
        lbl1.setGeometry(0, 0, 297, 1080)

        lbl1.mousePressEvent = self.contentclick

        # In this widget, the video will be drawn
        if sys.platform == "darwin":  # for MacOS
            from PyQt5.QtWidgets import QMacCocoaViewContainer
            videoframe = QMacCocoaViewContainer(0)
        else:
            videoframe = QtWidgets.QFrame(self)
        self.palette = videoframe.palette()
        self.palette.setColor(QPalette.Window, QColor(0, 0, 0))
        videoframe.setObjectName('videoview')
        videoframe.setPalette(self.palette)
        videoframe.setAutoFillBackground(True)
        videoframe.mousePressEvent = self.contentclick
        videoframe.setGeometry(QtCore.QRect(298, 0, 1622, 1080))

        global connection, roomid, readcheck, playlist, sorted_x, totalfile, oneloopindex, totalindexx, checkonetime, strings2, cou
        self.OpenFile(strings2[cou])
        insertdata(sorted_x[cou].DBindex, sorted_x[cou].playindex, totalindexx)
        cou += 1
        totalindexx += 1
        print(self.mediaplayer.get_state())
class VlcPlayerWidget(QMainWindow):
    """

    """
    showFullScreen_signal = pyqtSignal()
    showNormal_signal = pyqtSignal()

    def __init__(self, *args):
        super(VlcPlayerWidget, self).__init__()

        self.media_player_frame = QFrame()
        self.media_player = None
        self.instance = None
        self.set_media_player(args)
        self.widget = QWidget(self)
        self.setCentralWidget(self.widget)
        self.palette = self.media_player_frame.palette()
        self.palette.setColor(QPalette.Window, QColor(0, 0, 0))
        self.media_player_frame.setPalette(self.palette)
        self.media_player_frame.setAutoFillBackground(True)

        self.main_layout = QVBoxLayout()
        self.main_layout.setContentsMargins(0, 0, 0, 0)
        self.main_layout.setSpacing(0)

        self.current_url = None
        self.current_url_type = None

        self._init_ui()
        self.init_cfg()

    def _init_ui(self):
        """

        :return:
        """
        self.main_layout.addWidget(self.media_player_frame)
        self.widget.setLayout(self.main_layout)
        self.widget.setContextMenuPolicy(Qt.CustomContextMenu)
        self.widget.customContextMenuRequested.connect(self.custom_right_menu)
        self.setStyleSheet(
            f"background-image:url({PathHelper.get_img_path('live_null.png')}); "
        )

    def init_cfg(self):
        """

        :return:
        """
        self.vlc_set_volume(20)

    def set_media_player(self, *args):
        """ 获得并设置媒体播放器

        :param args:
        :return:
        """
        if args:
            self.instance = vlc.Instance(*args)
            self.media_player = self.instance.media_player_new()
        else:
            self.media_player = vlc.MediaPlayer()

        if get_system_platform() == CommonEnum.WindowsPlatform:
            self.media_player_frame = QFrame()
            self.media_player.set_hwnd(self.media_player_frame.winId())
        elif get_system_platform() == CommonEnum.LinuxPlatform:
            self.media_player_frame = QFrame()
            self.media_player.set_xwindow(self.media_player_frame.winId())
        elif get_system_platform() == CommonEnum.DarwinPlatform:
            from PyQt5.QtWidgets import QMacCocoaViewContainer
            self.media_player_frame = QMacCocoaViewContainer(0)
            self.media_player.set_nsobject(self.media_player_frame.winId())
        else:
            self.media_player.set_hwnd(self.media_player_frame.winId())

    def custom_right_menu(self, pos):
        """

        :param pos:
        :return:
        """
        if not (PlayerState.Load == PlayerEnum.LoadStopped
                or PlayerState.Load == PlayerEnum.LoadNothingSpecial):
            menu = QMenu()

            if PlayerState.Load == PlayerEnum.LoadPlaying:
                play_pause_opt = menu.addAction("暂停")
            elif PlayerState.Load == PlayerEnum.LoadPaused:
                play_pause_opt = menu.addAction("播放")
            else:
                play_pause_opt = menu.addAction("暂停")

            refresh_opt = menu.addAction("刷新")

            stop_opt = menu.addAction("停止")

            menu.addSeparator()

            if PlayerState.Size == PlayerEnum.SizeMax:
                fullscreen_opt = menu.addAction("复原")
            else:
                fullscreen_opt = menu.addAction("全屏")

            menu.addSeparator()

            mute_opt = menu.addAction("静音")

            action = menu.exec_(self.widget.mapToGlobal(pos))
            if action == play_pause_opt:
                if PlayerState.Load == PlayerEnum.LoadPlaying:
                    self.vlc_pause()
                else:
                    self.vlc_resume()
            elif action == refresh_opt:
                self.vlc_play(self.current_url, self.current_url_type)
            elif action == stop_opt:
                self.vlc_stop()
            elif action == fullscreen_opt:
                if PlayerState.Size == PlayerEnum.SizeMax:
                    self.vlc_set_size(False)
                else:
                    self.vlc_set_size(True)
            elif action == mute_opt:
                self.vlc_set_volume(-self.vlc_get_volume())

    def enterEvent(self, event: QEvent) -> None:
        """

        :param event:
        :return:
        """
        if not (PlayerState.Load == PlayerEnum.LoadStopped
                or PlayerState.Load == PlayerEnum.LoadNothingSpecial):
            # print("enterEvent")
            self.grabKeyboard()

    def leaveEvent(self, event: QEvent) -> None:
        """

        :param event:
        :return:
        """
        if not (PlayerState.Load == PlayerEnum.LoadStopped
                or PlayerState.Load == PlayerEnum.LoadNothingSpecial):
            # print("leaveEvent")
            self.releaseKeyboard()

    def mouseDoubleClickEvent(self, event: QMouseEvent) -> None:
        """

        :param event:
        :return:
        """
        if not (PlayerState.Load == PlayerEnum.LoadStopped
                or PlayerState.Load == PlayerEnum.LoadNothingSpecial):
            # print("mouseDoubleClickEvent")
            if PlayerState.Size == PlayerEnum.SizeMax:
                self.vlc_set_size(False)
            else:
                self.vlc_set_size(True)

    def keyPressEvent(self, event: QKeyEvent) -> None:
        """ 重写键盘按下事件

        :param event:
        :return:
        """
        if not (PlayerState.Load == PlayerEnum.LoadStopped
                or PlayerState.Load == PlayerEnum.LoadNothingSpecial):
            # print("keyPressEvent", event)
            if event.key() == Qt.Key_Escape:
                self.vlc_set_size(False)
            elif event.key() == Qt.Key_Left:
                if PlayerState.MrlType == PlayerEnum.MrlTypeLocal:
                    self.vlc_set_time(PlayerState.EachDecreaseTime)
            elif event.key() == Qt.Key_Right:
                if PlayerState.MrlType == PlayerEnum.MrlTypeLocal:
                    self.vlc_set_time(PlayerState.EachIncreaseTime)
            elif event.key() == Qt.Key_Up:
                self.vlc_set_volume(PlayerState.EachIncreaseVolume)
            elif event.key() == Qt.Key_Down:
                self.vlc_set_volume(PlayerState.EachDecreaseVolume)
            elif event.key() == Qt.Key_Space:
                if PlayerState.Load == PlayerEnum.LoadPlaying:
                    self.vlc_pause()
                else:
                    self.vlc_resume()
            else:
                pass

    def vlc_release(self):
        """ 释放资源

        :return:
        """
        return self.media_player.release()

    def vlc_play(self, url: str, url_type: PlayerEnum):
        """ 播放

        :param url:
        :param url_type:
        :return:
        """
        try:
            if url:
                # self.instance = vlc.Instance("--audio-visual=visual", "--effect-list=spectrometer",
                #                              "--effect-fft-window=flattop")
                # self.media_player = self.instance.media_player_new()

                self.current_url = url
                self.current_url_type = url_type
                self.media_player.set_mrl(url)
                self.media_player_frame.show()
                self.media_player.play()
                PlayerState.MrlType = url_type
                PlayerState.Load = PlayerEnum.LoadPlaying
            else:
                pass
        except Exception as e:
            print(f'[real-live-desktop]  play_url exception {e}')
            return False

    def vlc_pause(self):
        """ 暂停

        :return:
        """
        self.media_player.pause()
        PlayerState.Load = PlayerEnum.LoadPaused

    def vlc_resume(self):
        """ 恢复

        :return:
        """
        self.media_player.set_pause(0)
        PlayerState.Load = PlayerEnum.LoadPlaying

    def vlc_stop(self):
        """ 停止

        :return:
        """
        self.media_player_frame.hide()
        self.media_player.stop()
        PlayerState.Load = PlayerEnum.LoadStopped

    def vlc_get_time(self):
        """ 已播放时间,返回毫秒值

        :return:
        """
        return self.media_player.get_time()

    def vlc_get_length_or_all_time(self):
        """ 音视频总长度,返回毫秒值

        :return:
        """
        return self.media_player.get_length()

    def vlc_set_time(self, ms):
        """ 拖动指定的毫秒值处播放。成功返回0,失败返回-1 (需要注意,只有当前多媒体格式或流媒体协议支持才会生效)

        :param ms:
        :return:
        """
        _time = self.vlc_get_time() + ms
        _all_time = self.vlc_get_length_or_all_time()
        if _time <= 0:
            return self.media_player.set_time(0)
        elif _time >= _all_time:
            return self.media_player.set_time(_all_time)
        else:
            return self.media_player.set_time(_time)

    def vlc_get_volume(self):
        """ 获取当前音量(0~100)

        :return:
        """
        return self.media_player.audio_get_volume()

    def vlc_set_volume(self, volume):
        """ 设置当前音量

        :param volume:
        :return:
        """
        _volume = self.vlc_get_volume() + volume
        if _volume <= 0:
            PlayerState.Volume = PlayerEnum.VolumeMuted
            return self.media_player.audio_set_volume(0)
        elif _volume >= 100:
            PlayerState.Volume = PlayerEnum.VolumeUnmuted
            self.media_player.audio_set_volume(100)
        else:
            PlayerState.Volume = PlayerEnum.VolumeUnmuted
            self.media_player.audio_set_volume(_volume)

    def vlc_set_size(self, b_fullscreen: bool):
        """ 设置窗口大小

        :return:
        """
        if b_fullscreen:
            self.showFullScreen_signal.emit()
            # self.showFullScreen()
            self.media_player.set_fullscreen(True)
            PlayerState.Size = PlayerEnum.SizeMax
        else:
            self.showNormal_signal.emit()
            # self.showNormal()
            self.media_player.set_fullscreen(False)
            PlayerState.Size = PlayerEnum.SizeInitial

    def vlc_get_state(self):
        """ 返回当前状态

        :return:
        """
        # 0: 'NothingSpecial', 处于空闲状态,等待发出命令
        # 1: 'Opening', 正在打开媒体资源定位器(MRL)
        # 2: 'Buffering', 正在缓冲
        # 3: 'Playing', 正在播放媒体
        # 4: 'Paused', 处于暂停状态
        # 5: 'Stopped', 处于停止状态,此时关闭播放器
        # 6: 'Ended', 已到达当前播放列表的末尾
        # 7: 'Error', 遇到错误,无法继续
        return self.media_player.get_state()

    def vlc_set_position(self, float_val):
        """ 拖动当前进度,传入0.0~1.0之间的浮点数(需要注意,只有当前多媒体格式或流媒体协议支持才会生效)

        :param float_val:
        :return:
        """
        return self.media_player.set_position(float_val)

    def vlc_get_rate(self):
        """ 获取当前文件播放速率

        :return:
        """
        return self.media_player.get_rate()

    def vlc_set_rate(self, rate):
        """ 设置播放速率(如:1.2,表示加速1.2倍播放)

        :param rate:
        :return:
        """
        return self.media_player.set_rate(rate)

    def vlc_set_ratio(self, ratio):
        """ 设置宽高比率(如"16:9","4:3")

        :param ratio:
        :return:
        """
        # 必须设置为0,否则无法修改屏幕宽高
        self.media_player.video_set_scale(0)
        self.media_player.video_set_aspect_ratio(ratio)

    def vlc_add_callback(self, event_type, callback):
        """ 注册监听器

        :param event_type: VLC的监听器类型
        :param callback:
        :return:
        """
        self.media_player.event_manager().event_attach(event_type, callback)

    def vlc_remove_callback(self, event_type, callback):
        """ 移除监听器

        :param event_type:
        :param callback:
        :return:
        """
        self.media_player.event_manager().event_detach(event_type, callback)

    def vlc_set_marquee(self):
        """ 设置字幕

        :return:
        """
        # VideoMarqueeOption.Color :文本颜色,值为16进制数
        # VideoMarqueeOption.Enable:是否开启文本显示,1表示开启
        # VideoMarqueeOption.Opacity:文本透明度,0透明,255完全不透明
        # VideoMarqueeOption.Position:文本显示的位置
        # VideoMarqueeOption.Refresh:字符串刷新的间隔(毫秒)对时间格式字串刷新有用
        # VideoMarqueeOption.Size:文字大小,单位像素
        # VideoMarqueeOption.Text:要显示的文本内容
        # VideoMarqueeOption.Timeout:文本停留时间。0表示永远停留(毫秒值)
        # VideoMarqueeOption.marquee_X:设置显示文本的x坐标值
        # VideoMarqueeOption.marquee_Y:设置显示文本的y坐标值
        self.media_player.video_set_marquee_int(vlc.VideoMarqueeOption.Enable,
                                                1)
        self.media_player.video_set_marquee_int(vlc.VideoMarqueeOption.Size,
                                                28)
        self.media_player.video_set_marquee_int(vlc.VideoMarqueeOption.Color,
                                                0xff0000)
        self.media_player.video_set_marquee_int(
            vlc.VideoMarqueeOption.Position, vlc.Position.Bottom)
        self.media_player.video_set_marquee_int(vlc.VideoMarqueeOption.Timeout,
                                                0)
        self.media_player.video_set_marquee_int(vlc.VideoMarqueeOption.Refresh,
                                                10000)

    def vlc_update_marquee(self, content="%Y-%m-%d %H:%M:%S"):
        """ 设置字幕内容

        :param content: 默认为时间格式,会在屏幕下方显示当前时间,且每一秒刷新一次。
        :return:
        """
        self.media_player.video_set_marquee_string(vlc.VideoMarqueeOption.Text,
                                                   content)
Example #4
0
class MainWindow(QtWidgets.QMainWindow):
    def __init__(self):
        self.file_list = []
        super(MainWindow, self).__init__()
        uic.loadUi('../Vista/interface.ui', self)
        ''' Actions for label buttons of widget list '''
        self.Add.clicked.connect(self.Add_files)
        self.Select.clicked.connect(self.get_selected_item)
        self.Erase.clicked.connect(self.remove_selected_item)
        self.ChangePosition.clicked.connect(self.change_image)
        ''' Actions for Control the editor '''
        self.export_2.clicked.connect(self.Remderize_video)
        self.ChangeImage.clicked.connect(self.put_image)
        self.ChangeAudio.clicked.connect(self.put_audio)
        self.get_start.clicked.connect(self.set_init_frame)
        self.get_end.clicked.connect(self.set_end_frame)

        self.label2 = QtWidgets.QLabel("Ja'mapel cocunubo", self)
        self.label2.setText("")
        ''' Actions of menu bar '''
        self.actionExit.triggered.connect(self.exit)
        self.actionExport.triggered.connect(self.Remderize_video)
        self.actionOpen_Video.triggered.connect(self.OpenFile2)
        ''' Para entradas y salidas '''
        self.to_draw = None
        self.selected_item = None  # Variable con el item seleccionado por ej imagen ,a udio , video
        self.changes = None
        self.actvid = None
        self.actaud = None
        self.s1 = None
        self.s2 = None
        self.actimg = None
        self.tinicio = None
        self.tfin = None
        self.minframe = -1
        self.maxframe = -1
        self.newpath = None
        self.inicio = None  # Variable con frame de inicio
        self.final = None  # Variable con frame de terminacion
        self.x = None  # Variable con posicion relativa en x
        self.y = None  # Variable con posicion relative en y
        self.frame = None
        ''' DOnde puedes probar lo del VLC '''
        # creating a basic vlc instance
        self.instance = vlc.Instance()
        self.mediaPlayer = self.instance.media_player_new()
        # In this widget, the video will be drawn
        if sys.platform == "darwin":  # for MacOS
            from PyQt5.QtWidgets import QMacCocoaViewContainer
            self.videoPlayer = QMacCocoaViewContainer(0)
        else:
            self.videoPlayer = QtWidgets.QFrame()
        self.videoPlayer.resize(640, 360)
        self.palette = self.videoPlayer.palette()
        self.palette.setColor(QPalette.Window, QColor(0, 0, 0))
        self.videoPlayer.setPalette(self.palette)
        self.videoPlayer.setAutoFillBackground(True)
        self.isPaused = False
        self.Play.clicked.connect(self.play)
        self.Pause.clicked.connect(self.pause)
        self.Stop.clicked.connect(self.stop)

        self.Timer.setMaximum(1000)
        self.Timer.sliderMoved.connect(self.setPosition)
        self.Volume.sliderMoved.connect(self.setVolume)
        self.Volume.setRange(0, 100)
        self.lay.addWidget(self.videoPlayer)

        self.reloj = QtCore.QTimer(self)
        self.reloj.setInterval(1)
        self.reloj.timeout.connect(self.updateUI)

        self.t = Thread(target=self.counter)
        self.t2 = Thread(target=self.counter2)
        self.t3 = Thread(target=self.Draw_Image)

        self.timeEdit.setDisplayFormat("hh:mm:ss AP")
        self.timer = QtCore.QTimer(self)
        self.timer.timeout.connect(self.updateTime)
        self.timer.start(1000)

        self.t.start()
        self.t2.start()

        #self.selection.mousePressEvent = self.getPos

        #self.layout = QtWidgets.QVBoxLayout()
        self.counterpro.display(0)
        self.show()

    def updateTime(self):
        current = QtCore.QDateTime.currentDateTime()
        self.timeEdit.setTime(current.time())

    def getPos(self, event):
        x = event.pos().x()
        y = event.pos().y()
        self.xspin.setValue(x * 1.0)
        self.yspin.setValue(y * 1.0)
        self.x = x
        self.y = y
        self.label.hide()
        print(x, y)

        self.ChangePosition.setEnabled(True)
        self.spinBox.setEnabled(False)
        self.spinBox_2.setEnabled(False)
        self.xlabel_2.setEnabled(False)
        self.xlabel_3.setEnabled(False)

        if self.tinicio == None or self.actimg == None or self.actvid == None or self.x == None or self.y == None:
            print("Error cargando algo")
        else:
            pos = convertPos(self.x, self.y, self.actvid)
            self.changes = [
                self.actvid, self.actimg, self.tinicio, self.tfin, pos
            ]
            print("Exito , ", pos, self.actvid, self.actimg)

    def get_file(self, name):
        ret = None
        for x in self.file_list:
            if x.name == name:
                ret = x
                break
        print(ret.name)
        return ret

    def counter(self):
        while 1:
            self.counterpro.display(self.getPosition() * 1000)

    def counter2(self):
        while 1:
            self.Timer.setValue(self.getPosition() * 1000)

    def Add_files(self):
        image_formats = [".jpg", ".jpeg", ".png", ".ico", ".nef", ".bpm"]
        video_formats = [".avi", ".mp4", ".mov", ".mpeg", ".mkv"]
        audio_formats = [".mp3", ".wav"]
        options = QtWidgets.QFileDialog.Options()
        options |= QtWidgets.QFileDialog.DontUseNativeDialog
        fileName, _ = QtWidgets.QFileDialog.getOpenFileName(
            self,
            "Select Media Files",
            "",
            "All Files (*);;Image Files (*.jpeg)",
            options=options)
        name = os.path.basename(fileName)
        filename, file_extension = os.path.splitext(name)
        ubication = None
        if file_extension.lower() in image_formats:
            image = Image.open(fileName)
            image.thumbnail((500, 500), Image.ANTIALIAS)
            image.save('../Resources/' + "." + filename + ".png", 'PNG')
            ubication = '../Resources/' + "." + filename + ".png"
            typef = "image"
        if file_extension.lower() in audio_formats:
            ubication = "../Resources/audio-file.png"
            typef = "audio"
        if file_extension.lower() in video_formats:
            ubication = "../Resources/video-file.png"
            typef = "video"
        if ubication != None:
            pixmap = QIcon(ubication)
            item = QtWidgets.QListWidgetItem(pixmap, filename)
            self.file_list.append(MediaFile(filename, fileName, typef))
            self.filelist.addItem(item)

    def get_selected_item(self):
        self.ChangePosition.setEnabled(False)
        self.ChangeImage.setEnabled(False)
        self.ChangeAudio.setEnabled(False)
        self.spinBox.setEnabled(False)
        self.spinBox_2.setEnabled(False)
        self.xlabel_2.setEnabled(False)
        self.xlabel_3.setEnabled(False)
        self.get_start.setEnabled(False)
        self.get_end.setEnabled(False)
        if len(self.filelist.selectedItems()) > 0:
            self.selected_item = self.get_file(
                self.filelist.selectedItems()[0].text())
            if self.selected_item.typef == "image":
                self.ChangeImage.setEnabled(True)
                self.actimg = self.selected_item.path
                self.spinBox.setEnabled(True)
                self.spinBox_2.setEnabled(True)
                self.xlabel_2.setEnabled(True)
                self.xlabel_3.setEnabled(True)
                self.get_start.setEnabled(True)
                self.get_end.setEnabled(True)
            elif self.selected_item.typef == "audio":
                self.ChangeAudio.setEnabled(True)
                self.spinBox.setEnabled(True)
                #self.spinBox_2.setEnabled(True)
                self.xlabel_2.setEnabled(True)
                #self.xlabel_3.setEnabled(True)
                self.actaud = self.selected_item.path
            if self.selected_item.typef == "video":
                self.OpenFile(self.selected_item.path)
                self.actvid = self.selected_item.path

    def set_init_frame(self):
        self.spinBox.setValue(int(round(self.getPosition() * 1000)))

    def set_end_frame(self):
        self.spinBox_2.setValue(int(round(self.getPosition() * 1000)))

    def calculateTime(self):
        self.minframe = self.spinBox.value()
        self.maxframe = self.spinBox_2.value()

        framerate = self.mediaPlayer.get_fps()
        startf = self.spinBox.value()
        endf = self.spinBox_2.value()
        self.tinicio = startf / framerate
        self.tfin = endf / framerate

    def remove_selected_item(self):
        listItems = self.filelist.selectedItems()
        if len(listItems) == 0: return
        self.filelist.takeItem(self.filelist.row(listItems[0]))

    ''' Functions for edit the video '''
    ''' Todos los metodos que consideres dejalos comentados y pone con que lo linkeo '''

    def Remderize_video(self):  # Metodo con funcion de remderizar
        options = QtWidgets.QFileDialog.Options()
        options |= QtWidgets.QFileDialog.DontUseNativeDialog
        self.newpath, _ = QtWidgets.QFileDialog.getSaveFileName(
            self, "Select Media Files", "", "All Files (*)", options=options)

        if False:
            print("Error cargando algo")
        else:
            pid = os.fork()
            if pid == 0:
                print(self.changes[0], self.newpath, self.changes[1],
                      self.changes[2], self.changes[3], self.changes[4])
                addImage(self.changes[0], self.newpath, self.changes[1],
                         self.changes[2], self.changes[3], self.changes[4])
                exit(0)

    def put_image(self):  # Metodo que pone la imagen
        #self.label.show()
        self.get_start.setEnabled(True)
        self.get_end.setEnabled(True)
        self.label = QtWidgets.QLabel("Ja'mapel", self)
        self.label.setText("")
        self.label.setGeometry(QtCore.QRect(19, 44, 640, 360))
        self.label.setMinimumSize(QtCore.QSize(640, 360))
        self.label.setMaximumSize(QtCore.QSize(640, 360))
        self.label.setCursor(QtCore.Qt.PointingHandCursor)
        self.label.mousePressEvent = self.getPos
        self.label.setAttribute(QtCore.Qt.WA_TranslucentBackground)
        self.label.show()
        self.ChangeImage.setEnabled(False)
        self.calculateTime()
        self.make_mini_image()
        self.t3.start()

    def change_image(self):  # Metodo que pone la imagen

        #self.label.show()
        self.label = QtWidgets.QLabel("Ja'mapel", self)
        self.label.setText("")
        self.label.setGeometry(QtCore.QRect(19, 44, 640, 360))
        self.label.setMinimumSize(QtCore.QSize(640, 360))
        self.label.setMaximumSize(QtCore.QSize(640, 360))
        self.label.setCursor(QtCore.Qt.PointingHandCursor)
        self.label.mousePressEvent = self.getPos
        self.label.setAttribute(QtCore.Qt.WA_TranslucentBackground)
        self.label.show()
        self.ChangeImage.setEnabled(False)

    def chg_image(self):  # Metodo que pone la imagen
        self.calculateTime()
        if self.tinicio == None or self.actimg == None or self.actvid == None or self.x == None or self.y == None:
            print("Error cargando algo")
        else:
            pos = convertPos(self.x, self.y, self.actvid)
            self.changes = [
                self.actvid, self.actimg, self.tinicio, self.tfin, pos
            ]

    def exit(self):
        pos = [self.x, self.y]
        self.changes.append(
            [self.actvid, self.actimg, self.tinicio, self.tfin, pos])

    def put_audio(self):  # Metodo que pone el audio
        self.calculateTime()
        if self.tinicio == None or self.actaud == None or self.actvid == None:
            print("Error cargando algo")
        else:
            addSound(self.tinicio, self.actaud, self.actvid)

    def exit(self):
        window = Form()
        window.show()
        window.exec_()
        exit(0)

    def play(self):
        #if self.mediaPlayer.is_playing():
        self.mediaPlayer.play()
        self.isPaused = False
        self.videoPlayer.resize(640, 360)

    def pause(self):
        #if not self.mediaPlayer.is_playing():
        self.mediaPlayer.pause()
        self.isPaused = True

    def stop(self):
        self.mediaPlayer.stop()

    def setVolume(self, Volume):
        self.mediaPlayer.audio_set_volume(Volume)

    def setPosition(self, position):
        self.mediaPlayer.set_position(position / 1000.0)

    def getPosition(self):
        return self.mediaPlayer.get_position()

    def updateUI(self):
        self.Timer.setValue(self.mediaplayer.get_position() * 1000)
        self.reloj.stop()
        if not self.isPaused:
            self.stop()

    def make_mini_image(self):
        image = Image.open(self.actimg)
        w, h = image.size
        self.s1 = w / 2
        self.s2 = h / 2
        image.thumbnail((self.s1, self.s2), Image.ANTIALIAS)
        image.save('../Resources/' + "." + "DRAW" + ".png", 'PNG')
        self.to_draw = '../Resources/' + "." + "DRAW" + ".png"

    def OpenFile(self, filename=None):
        '''
        options = QFileDialog.Options()
        options |= QFileDialog.DontUseNativeDialog
        filename, _ = QFileDialog.getOpenFileName(self,"Select Media Files", "","All Files (*);;Image Files (*.jpeg)", options=options)
        '''
        if sys.version < '3':
            filename = unicode(filename)
        self.media = self.instance.media_new(filename)
        self.mediaPlayer.set_media(self.media)
        self.media.parse()

        if sys.platform.startswith('linux'):
            self.mediaPlayer.set_xwindow(self.videoPlayer.winId())
        elif sys.platform == "win32":
            self.mediaPlayer.set_hwnd(self.videoPlayer.winId())
        elif sys.platform == "darwin":
            self.mediaPlayer.set_nsobject(int(self.videoPlayer.winId()))
        self.videoPlayer.resize(640, 360)
        self.play()

    def OpenFile2(self):

        options = QtWidgets.QFileDialog.Options()
        options |= QtWidgets.QFileDialog.DontUseNativeDialog
        filename, _ = QtWidgets.QFileDialog.getOpenFileName(
            self,
            "Select Media Files",
            "",
            "All Files (*);;Image Files (*.jpeg)",
            options=options)

        if sys.version < '3':
            filename = unicode(filename)
        self.media = self.instance.media_new(filename)
        self.mediaPlayer.set_media(self.media)
        self.media.parse()

        if sys.platform.startswith('linux'):
            self.mediaPlayer.set_xwindow(self.videoPlayer.winId())
        elif sys.platform == "win32":
            self.mediaPlayer.set_hwnd(self.videoPlayer.winId())
        elif sys.platform == "darwin":
            self.mediaPlayer.set_nsobject(int(self.videoPlayer.winId()))
        self.videoPlayer.resize(640, 360)
        self.play()

    def Draw_Image(self):
        while 1:
            sleep(0.05)
            var = self.getPosition() * 1000
            #print(" tengo ",var," quiero ", self.minframe , " con un " , self.maxframe)
            if var >= self.minframe and var <= self.maxframe:
                if self.actimg != None:
                    self.label2.setGeometry(
                        QtCore.QRect(self.x, self.y, self.s1, self.s2))
                    self.label2.setMinimumSize(QtCore.QSize(self.s1, self.s2))
                    self.label2.setMaximumSize(QtCore.QSize(self.s1, self.s2))
                    self.label2.setAttribute(
                        QtCore.Qt.WA_TranslucentBackground)
                    pixmap = QPixmap(self.to_draw)
                    self.label2.setPixmap(pixmap)
                    self.label2.setMask(pixmap.mask())
                    self.label2.show()
            else:
                self.label2.hide()