#include "widget.h" #include #include #include #include #include #include /* rtsp://122.192.35.80:554/live/tv01 江苏城市 rtsp://122.192.35.80:554/live/tv02 江苏卫视 rtsp://122.192.35.80:554/live/tv03 江苏综艺 rtsp://122.192.35.80:554/live/tv07 CCTV4 rtsp://122.192.35.80:554/live/tv08 旅游卫视 rtsp://122.192.35.80:554/live/tv08 NJTV新闻综合 rtsp://122.192.35.80:554/live/tv10 湖南卫视 rtsp://122.192.35.80:554/live/tv11 东方卫视 rtsp://122.192.35.80:554/live/tv12 档案(北京) rtsp://122.192.35.80:554/live/tv14 CCTV1 rtsp://122.192.35.80:554/live/tv16 辽宁卫视 rtsp://122.192.35.80:554/live/tv20 MursTv rtsp://122.192.35.80:554/live/tv28 幸福Tv rtsp://122.192.35.80:554/live/tv30 CCTV3 rtsp://122.192.35.80:554/live/tv31 CCTV6 rtsp://122.192.35.80:554/live/tv50 靓妆 rtsp://122.192.35.80:554/live/tv51 江苏公共 rtsp://122.192.35.80:554/live/tv60 新闻综合(江苏) rtsp://122.192.35.80:554/live/tv61 新闻 rtsp://122.192.35.80:554/live/tv62 盐城 rtsp://122.192.35.80:554/live/tv63 rtsp://122.192.35.80:554/live/tv73 新闻综合 */ using namespace QtAV; Widget::Widget(QWidget *parent) : QWidget(parent) { setWindowTitle("A test for shared video renderer. QtAV" QTAV_VERSION_STR_LONG " wbsecg1@gmail.com"); QVBoxLayout *main_layout = new QVBoxLayout; QHBoxLayout *btn_layout = new QHBoxLayout; renderer = new WidgetRenderer; renderer->setFocusPolicy(Qt::StrongFocus); renderer->resizeVideo(640, 480); for (int i = 0; i < 2; ++i) { player[i] = new AVPlayer(this); player[i]->setRenderer(renderer); QVBoxLayout *vb = new QVBoxLayout; play_btn[i] = new QPushButton(this); play_btn[i]->setText(QString("Play-%1").arg(i)); file_btn[i] = new QPushButton(this); file_btn[i]->setText(QString("Choose video-%1").arg(i)); connect(play_btn[i], SIGNAL(clicked()), SLOT(playVideo())); connect(file_btn[i], SIGNAL(clicked()), SLOT(setVideo())); vb->addWidget(play_btn[i]); vb->addWidget(file_btn[i]); btn_layout->addLayout(vb); } QPushButton *net_btn = new QPushButton(tr("Test online video(rtsp)")); connect(net_btn, SIGNAL(clicked()), SLOT(testRTSP())); main_layout->addWidget(renderer); main_layout->addWidget(net_btn); main_layout->addLayout(btn_layout); setLayout(main_layout); resize(720, 600); } Widget::~Widget() { } void Widget::playVideo() { for (int i = 0; i < 2; ++i) player[i]->pause(true); QPushButton *btn = qobject_cast(sender()); int idx = btn->text().section('-', 1).toInt(); player[idx]->pause(false); } void Widget::setVideo() { QString v = QFileDialog::getOpenFileName(0, "Select a video"); if (v.isEmpty()) return; QPushButton *btn = qobject_cast(sender()); int idx = btn->text().section('-', 1).toInt(); QString oldv = player[idx]->file(); if (v == oldv) return; for (int i = 0; i < 2; ++i) player[i]->pause(true); player[idx]->stop(); player[idx]->setFile(v); player[idx]->play(); } void Widget::testRTSP() { for (int i = 0; i < 2; ++i) player[i]->stop(); player[0]->play("rtsp://122.192.35.80:554/live/tv11"); player[0]->pause(true); player[1]->play("rtsp://122.192.35.80:554/live/tv10"); }