Example #1
0
    def addMedia(self, content: QMediaContent, media_id: int) -> bool:
        """Append the media `content` to the playlist.

        Parameters
        ----------
        content: QMediaContent
            The media to append.
        media_id: int
            The ID of the media in the model.

        Returns
        -------
        bool
            Always True.

        """
        row = self._get_row(media_id)

        self.mediaAboutToBeInserted.emit(row, row)
        self._media[media_id] = content
        self.mediaInserted.emit(row, row)

        file_name = content.canonicalUrl().fileName()
        log.debug(f"Added media with ID {media_id}: {file_name}")

        return True
Example #2
0
    def mediaChanged(self, media: QtMultimedia.QMediaContent):
        # print(media, vars(media), dir(media))
        raw_path = media.canonicalUrl().toString()
        if raw_path.strip() != "":
            print(f"{raw_path=}")
            probe = FFProbe(raw_path)

            for k, v in probe.info.items():
                print(f"\t{k}: {v}")
            self.view.progress_bar.setRange(0, probe.duration_ms)

            self.view.current_song.setText(
                f"{probe.listing} ({probe.duration_str})")
 def setMedia(self,
              media: QtMultimedia.QMediaContent,
              stream: QtCore.QIODevice = None,
              realDuration=None) -> None:
     self.blockSignals(True)
     super().setMedia(media, stream)
     self.blockSignals(False)
     self._realDuration = realDuration
     self._lastFakePosition = 0
     self._bugRate = 0.0
     if realDuration is None:
         filename = media.canonicalUrl().toLocalFile()
         file = taglib.File(filename)
         bitrate = file.bitrate
         file.close()
         self._realDuration = Path(filename).stat().st_size * 8 // bitrate