このページでは

メディアプレーヤーの例

Qt Widgets を使用したオーディオおよびビデオの再生。

動画の再生とコントロールパネルが表示されたメディアプレーヤー

Media Playerは、さまざまなコーデックを使用してオーディオおよびビデオファイルを再生できる、シンプルなマルチメディアプレーヤーを実演します。

サンプルの実行

以下の手順でサンプルを実行できます。

このサンプルでは、QVideoWidget に渡されたQMediaPlayer オブジェクトを使用して、ビデオ出力を制御しています。また、アプリケーションにプレイリスト機能を付与するために、QMediaPlaylist オブジェクトも使用しています。QMediaPlaylist は Qt 6 で API から削除されましたが、このサンプルにはその実装が含まれています。

オーディオレベルメーターは、再生中のピークレベルとRMSレベルを表示します。これは、QAudioBufferOutput をQMediaPlayer に設定し、それが発する各QAudioBuffer を別スレッドで処理し、QWidget::paintEvent を通じて値を可視化することで実装されています。

ダイアログ上の再生や停止などの各種機能を有効にするには、ボタンがクリックされた際のイベントによってplay()およびstop()シグナルが発信され、これらはQMediaPlayer のplay()およびstop()スロットに接続されています。

connect(controls, SIGNAL(play()), player, SLOT(play()));
connect(controls, SIGNAL(pause()), player, SLOT(pause()));
connect(controls, SIGNAL(stop()), player, SLOT(stop()));

音量を取得し(ユーザーインターフェース上の表示を更新することも可能です)

controls->setVolume(player->volume());

また、ウィジェットの「音量」を変更することで、実際の音量を変更することも可能です

connect(controls, SIGNAL(changeVolume(int)), player, SLOT(setVolume(int)));

また、この例では、QVideoWidget オブジェクトを使用して動画のプロパティを変更することもできます。ボタンを 1 回クリックするだけで全画面モードに切り替えたり、元の状態に戻したりできます。

サンプルプロジェクト @ code.qt.io

© 2026 The Qt Company Ltd. Documentation contributions included herein are the copyrights of their respective owners. The documentation provided herein is licensed under the terms of the GNU Free Documentation License version 1.3 as published by the Free Software Foundation. Qt and respective logos are trademarks of The Qt Company Ltd. in Finland and/or other countries worldwide. All other trademarks are property of their respective owners.