Código de Python - Reproductor de vídeo (.avi).

Imágen de perfil
Val: 712
Bronce
Ha aumentado 1 puesto en Python (en relación al último mes)
Gráfica de Python

Reproductor de vídeo (.avi).gráfica de visualizaciones


Python

Actualizado el 2 de Octubre del 2020 por Antonio (75 códigos) (Publicado el 2 de Agosto del 2020)
5.061 visualizaciones desde el 2 de Agosto del 2020
Reproductor de vídeos (en formato .avi). El vídeo a reproducir se selecciona con el botón "Buscar". Una vez cargado el vídeo, la reproducción se inicia con el botón "Iniciar vídeo". A su vez, el usuario puede moverse por el vídeo usando el slider inferior así como cambiar el volumen con el slider derecho.
CUALQUIER FALLO O DUDA, NO DUDEN EN COMENTARMELO.


reproductor

Requerimientos

REQUERIMIENTOS:
Lenguaje: Python
Librerías: PyQt5, functools, sys

2.0
estrellaestrellaestrellaestrellaestrella(1)

Actualizado el 16 de Octubre del 2020 (Publicado el 2 de Agosto del 2020)gráfica de visualizaciones de la versión: 2.0
5.063 visualizaciones desde el 2 de Agosto del 2020
estrellaestrellaestrellaestrellaestrella
estrellaestrellaestrellaestrella
estrellaestrellaestrella
estrellaestrella
estrella

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
#!/usr/bin/env python
# -*- coding: utf-8 -*-
import sys
from functools import partial
from PyQt5.QtCore import QEvent, QUrl, Qt, QTimer, QTime
from PyQt5.QtWidgets import (QApplication, QHBoxLayout, QMainWindow,
                             QWidget, QPushButton, QSlider,
                             QVBoxLayout, QFileDialog, QLabel)
from PyQt5.QtMultimedia import QMediaContent, QMediaPlayer
from PyQt5.QtMultimediaWidgets import QVideoWidget
from PyQt5 import QtGui, QtCore
import datetime
 
class MainWindow(QMainWindow):
 
    def __init__(self):
        super().__init__()
 
        self.widget = QWidget(self)
        self.layout = QVBoxLayout()
        self.bottom_layout = QHBoxLayout()
        self.video_widget = QVideoWidget(self)
        self.media_player = QMediaPlayer()
 
        self.search_button = QPushButton("Buscar",self)
        self.play_button = QPushButton("Iniciar Vídeo", self)
        self.stop_button = QPushButton("Volver al principio", self)
        self.title_label = QLabel("",self)
        self.current = 0
        self.time_label = QLabel('',self)
        self.title_label.setStyleSheet('QLabel {background-color: black; color: green;}')
        self.time_label.setStyleSheet('QLabel {background-color: black; color: red;}')
        self.time_label.setAlignment(QtCore.Qt.AlignCenter)
        self.time_label.setFixedWidth(68)
        self.volume_label = QLabel("VOLUMEN:",self)
        self.play_button.setEnabled(False)
        self.stop_button.setEnabled(False)
 
 
        self.seek_slider = QSlider(Qt.Horizontal)
        self.volume_slider = QSlider(Qt.Horizontal)
        self.volume_slider.setRange(0, 100)
        self.volume_slider.setValue(self.media_player.volume())
        self.seek_slider.sliderMoved.connect(self.media_player.setPosition)
        self.volume_slider.sliderMoved.connect(self.media_player.setVolume)
        self.media_player.positionChanged.connect(self.seek_slider.setValue)
        self.media_player.durationChanged.connect(partial(self.seek_slider.setRange, 0))
 
        self.layout.addWidget(self.video_widget)
        self.layout.addLayout(self.bottom_layout)
 
        self.bottom_layout.addWidget(self.search_button)
        self.bottom_layout.addWidget(self.title_label)
        self.bottom_layout.addWidget(self.time_label)
        self.bottom_layout.addWidget(self.play_button)
        self.bottom_layout.addWidget(self.stop_button)
        self.bottom_layout.addWidget(self.volume_label)
        self.bottom_layout.addWidget(self.volume_slider)
        self.layout.addWidget(self.seek_slider)
 
        self.search_button.clicked.connect(self.openFile)
        self.play_button.clicked.connect(self.play_clicked)
        self.stop_button.clicked.connect(self.stop_clicked)
        self.media_player.stateChanged.connect(self.state_changed)
 
        self.video_widget.installEventFilter(self)
        self.setWindowTitle("Reproductor de video (.avi)")
        self.resize(800, 515)
        self.layout.setContentsMargins(0, 0, 0, 0)
        self.bottom_layout.setContentsMargins(0, 0, 0, 0)
        self.widget.setLayout(self.layout)
        self.setCentralWidget(self.widget)
 
        timer2 = QTimer(self)
 
        timer2.timeout.connect(self.displayTime)
 
        timer2.start(100)
 
        self.active_timer = False
 
    def move_text(self):
        if self.text != "":
            lista = list(self.text)
            dele = lista.pop(0)
            lista.append(dele)
            tf = "".join(lista)
            self.title_label.setText(tf)
            self.text = tf
 
 
    def play_clicked(self):
        if (self.media_player.state() in
            (QMediaPlayer.PausedState, QMediaPlayer.StoppedState)):
            self.media_player.play()
 
        else:
            self.media_player.pause()
 
 
    def stop_clicked(self):
        self.media_player.stop()
 
 
    def state_changed(self, newstate):
        states = {
            QMediaPlayer.PausedState: "Continuar",
            QMediaPlayer.PlayingState: "Pausar",
            QMediaPlayer.StoppedState: "Reproducir"
        }
        self.play_button.setText(states[newstate])
        self.stop_button.setEnabled(newstate != QMediaPlayer.StoppedState)
 
 
    def eventFilter(self, obj, event):
        if event.type() == QEvent.MouseButtonDblClick:
            obj.setFullScreen(not obj.isFullScreen())
        return False
 
    def openFile(self):
        fileName,_ = QFileDialog.getOpenFileName(self,"Archivo de video", "/home","AVI files (*.avi)")
        if fileName != '':
            timer = QTimer(self)
            self.videoName = fileName.split("/")[-1]
            self.text = "-"+self.videoName+"-"
            if self.active_timer == False:
                timer.timeout.connect(self.move_text)
                self.active_timer = True
                timer.start(650)
            VIDEO_PATH = fileName
            self.media_player.setMedia(
            QMediaContent(QUrl.fromLocalFile(VIDEO_PATH)))
            self.media_player.setVideoOutput(self.video_widget)
            self.play_button.setEnabled(True)
            self.stop_button.setEnabled(True)
 
    def displayTime(self):
        self.current = self.media_player.position()
        self.timeClock = str(datetime.timedelta(seconds=int(self.current/1000)))
        #time_parts = self.timeClock.split(":")
        #if int(time_parts[0]) < 10:
            #self.time_label.setText("0"+self.timeClock)
        #else:
        self.time_label.setText(self.timeClock)
 
 
if __name__ == "__main__":
    app = QApplication(sys.argv)
    window = MainWindow()
    window.show()
sys.exit(app.exec_())



Comentarios sobre la versión: 2.0 (1)

RIG
17 de Febrero del 2021
estrellaestrellaestrellaestrellaestrella
Hola Amigo,
Soy nuevo con Python y me tope con tu código con archivos AVI funciona bárbaro pero no me funciona con archivos mp4.
Modifique el filtro del cuadro de dialogo, entonces ahora me deja seleccionarlos pero no me los muestra.
1
fileName, _ = QFileDialog.getOpenFileName(self, "Archivo de video", "/home", "AVI files (*.avi);;MP4 files (*.mp4)")

Si puede ayudarme te lo agradeceria
Saludos
Ramon
Responder

Comentar la versión: 2.0

Nombre
Correo (no se visualiza en la web)
Valoración
Comentarios...
CerrarCerrar
CerrarCerrar
Cerrar

Tienes que ser un usuario registrado para poder insertar imágenes, archivos y/o videos.

Puedes registrarte o validarte desde aquí.

Codigo
Negrita
Subrayado
Tachado
Cursiva
Insertar enlace
Imagen externa
Emoticon
Tabular
Centrar
Titulo
Linea
Disminuir
Aumentar
Vista preliminar
sonreir
dientes
lengua
guiño
enfadado
confundido
llorar
avergonzado
sorprendido
triste
sol
estrella
jarra
camara
taza de cafe
email
beso
bombilla
amor
mal
bien
Es necesario revisar y aceptar las políticas de privacidad

http://lwp-l.com/s6385