QT5 Self-created simple music video player (basic version)

Source: Internet
Author: User

Recently the code wrote a lot, but did not pass much, another day to find a time to comb under! Don't say much nonsense,


Qt5 seemingly in the audio and video processing and QT4 different, Qt4 with Phonon,qt5 with Qmediaplayer.


1. Modify the Pro file

Add QT +=multimedia//audio processing to Pro files

Add QT +=multimediawidget//Support Qvideowidget in pro file, play video


2.

Window set to support playback of video streams

setAttribute (Qt::wa_translucentbackground,true );


player = new qmediaplayer (th is,0);

Playlist = new Qmediaplaylist (this);
Videowidget = new Qvideowidget (this);
NEXTBTN = new Qpushbutton (tr ("Next"), this);
Qgridlayout *mainlayout = new Qgridlayout (this);

Add a media file to a playlist
Playlist->addmedia (Qurl::fromlocalfile ("C:/users/zgw/music/old.mp3"));
Playlist->addmedia (Qurl::fromlocalfile ("C:/users/zgw/music/her.mp3"));
Playlist->addmedia (Qurl::fromlocalfile ("C:/users/zgw/music/hua.mp3"));
Playlist->addmedia (Qurl::fromlocalfile ("c:/users/zgw/music/wildlife.wmv"));
Where the settings list starts playing
Playlist->setcurrentindex (Playindex);
Player->setplaylist (playlist);
Player->setvideooutput (Videowidget);
Videowidget->show ();

Mainlayout->addwidget (Videowidget, 1, 1, 3, 3);
Mainlayout->addwidget (NEXTBTN, 4, 1, 1, 1);
This->setlayout (mainlayout);
Set the volume to start playing
Player->setvolume (100);
Player->play (); Connect (nextbtn, SIGNAL (clicked ()), this, SLOT (On_next_click ()));



void mywidget::on_next_click()

{
if (Playindex = = 4)
{
Playindex = 1;
}
Else
{
playindex++;
}

Player->stop ();
Playlist->setcurrentindex (Playindex);
Player->play ();
The functionality is simple and the interface is simple--| | |. The next step continues to expand the function: 1, playlist visualization, 2, manually add playback files, 3, the realization of network functions (download songs, cache listen to songs) 4, lyrics function



QT5 Self-created simple music video player (basic version)

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.