Qt 5.5:在媒体播放器中加载视频时设置的持续时间

时间:2015-07-29 16:11:37

标签: qt video

我想知道媒体播放器的持续时间字段何时会被您尝试播放的视频更新。

例如,如果我加载视频并点击播放它,我可以读取播放视频“onPressed”时的持续时间 但是,如果我加载视频“onPressed”我可以播放它,但持续时间设置为0.

此字段何时更新,或者如何动态加载视频并访问持续时间?

import unittest
from unittest.mock import mock_open, patch

import module_under_test


def func():
    with open("somefile") as f:
        return f.read()


class MyTestCase(unittest.TestCase):

    def test_open(self):
        data = "some data"
        with patch.object(module_under_test, "open", mock_open(read_data=data), create=True):
            result = module_under_test.func()

        self.assertEqual(result, data)


if __name__ == "__main__":
    unittest.main()

}

1 个答案:

答案 0 :(得分:0)

I suppose the original OP has already a solution as it's an old question, but I post that in order to help anyone who has the same question. As far as I know, you can check any metadata property once the media is loaded:

Video{
    id: metaData
    source: "your source here...";
    onStatusChanged: {
        if(status === MediaPlayer.Loaded){
            console.log(metaData.duration);
        }
    }
}

Hope help someone.