Note that there are some explanatory texts on larger screens.

plurals
  1. POHow to get the total duration of media being played in PyQt4?
    primarykey
    data
    text
    <p>I am trying to write a small audio player in PyQt4. This is a part of the code I've written:</p> <pre><code>class Player(QMainWindow): def __init__(self, fileLoc, parent = None): super(QMainWindow, self).__init__() self.totTime = 0 self.audioOutput = Phonon.AudioOutput(Phonon.MusicCategory, self) self.mediaObject = Phonon.MediaObject(self) self.mediaObject.setTickInterval(1000) self.mediaObject.tick.connect(self.tick) self.mediaObject.stateChanged.connect(self.stateChanged) Phonon.createPath(self.mediaObject, self.audioOutput) #Define Play, Pause and Stop actions self.playAction = QAction(self.style().standardIcon(QStyle.SP_MediaPlay), "Play", self, enabled = False, triggered = self.mediaObject.play) self.pauseAction = QAction(self.style().standardIcon(QStyle.SP_MediaPause), "Pause", self, enabled = False, triggered = self.mediaObject.pause) self.stopAction = QAction(self.style().standardIcon(QStyle.SP_MediaStop), "Stop", self, enabled = False, triggered = self.mediaObject.stop) #Initiate User Interface self.userInterface() self.timeDisp.display('00:00') self.mediaObject.setCurrentSource(Phonon.MediaSource(fileLoc)) self.mediaObject.play() def tick(self, time): self.displayTime = QTime(0, (time / 60000) % 60, (time / 1000) % 60) self.timeDisp.display(self.displayTime.toString('mm:ss')) </code></pre> <p>My problem is, I am unable to figure out how to get the total duration of the file being currently played. I have tried printing the output of mediObject.totalTime() at the end of <strong>init</strong>(). But it returned -1 for all the videos. mediObject.totalTime() inside tick() is returning incorrect duration (10 - 15 seconds longer than the actual duration). </p> <p>Also, I may have to access the value of total duration from outside the class. How can I do this?</p> <p>Thanks in advance.</p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload