Qt Media Player

Source: Internet
Author: User

It can be displayed in full screen to solve the layout problem and display the time progress ..CodeTry to be as simple as possible, basically perfect, note the need to decode the package

 

If you need QT based mplayer Media Player: http://blog.csdn.net/buafnlin/archive/2011/02/04/6172415.aspx

 

 

Mainwindow. cpp

 

# Include "mainwindow. H"

 

# Include "ui_main1_1_h"

# Include <qtcore/qsettings>

# Include <qtcore/qtimer>

# Include <qtgui/qaction>

# Include <qtgui/qapplication>

# Include <qtgui/qbitmap>

# Include <qtgui/qlineargradient>

# Include <qtgui/qmouseevent>

# Include <qtgui/qpainter>

# Include <qmessagebox>

# Include <qkeyevent>

# Include <qsound>

# Include "qfiledialog"

# Include "qdebug"

# Include "phonon"

# Include "qlabel"

# Include <qvboxlayout>

# Include <qhboxlayout>

# Include <qwidget>

# Include "phonon/videowidget"

# Include "qtime"

# Include <qdockwidget>

# Include <qaction>

Mainwindow: mainwindow (qwidget * parent ):

Qmainwindow (parent ),

UI (new UI: mainwindow)

{

UI-> setupui (this );

UI-> widget-> installeventfilter (this );

Media = new phonon: mediaobject;

// Media-> setcurrentsource (phonon: mediasource ("../puppet. mpg "));

W1 = new qwidget (this );

W3 = new qwidget (this );

Timelcd = new qlcdnumber (this );

Vwidget = new phonon: videowidget (W1 );

Phonon: createpath (Media, vwidget );

Vwidget-> setaspectratio (phonon: videowidget: aspectratioauto );

Aoutput = new phonon: audiooutput (phonon: videocategory );

Phonon: createpath (Media, aoutput );

// Qlabel * L1 = new qlabel (qstring: fromlocal8bit ("playback progress :"));

// Qlabel * L2 = new qlabel (qstring: fromlocal8bit ("volume :"));

Volumeslider = new phonon: volumeslider;

Volumeslider-> setaudiooutput (aoutput );

Volumeslider-> setsizepolicy (qsizepolicy: Maximum, qsizepolicy: Maximum );

Phonon: seekslider * seekslider = new phonon: seekslider;

Seekslider-> setmediaobject (media );

Timelcd-> display ("00:00 ");

Qvboxlayout * vlayout = new qvboxlayout;

Vlayout-> addwidget (vwidget );

Vwidget-> resize (1024,768 );

W1-> setlayout (vlayout );

// Qhboxlayout * H1 = new qhboxlayout;

// H1-> addwidget (L1 );

// H1-> addwidget (seekslider );

// H1-> addwidget (timelcd );

// Qhboxlayout * H2 = new qhboxlayout;

// H2-> addwidget (L2 );

// H2-> addwidget (volumeslider );

// H2-> addwidget (ui-> widget_4 );

// Qvboxlayout * vlayout1 = new qvboxlayout;

// Vlayout1-> addlayout (H1 );

// Vlayout1-> addlayout (H2 );

// W3-> setlayout (vlayout1 );

// Qhboxlayout * hlayout1 = new qhboxlayout;

// Hlayout1-> addwidget (W3 );

// Qvboxlayout * vlayout3 = new qvboxlayout;

// Vlayout3-> addwidget (W1 );

// Vlayout3-> addlayout (hlayout1 );

// Vlayout3-> addwidget (ui-> widget_4 );

// W2 = new qwidget (this );

// W2-> setlayout (vlayout3 );

This-> setcentralwidget (W1 );

Qdockwidget * shapesdockwidget1 = new qdockwidget (qstring: fromlocal8bit ("playback progress "));

Shapesdockwidget1-> setwidget (seekslider );

// Shapesdockwidget1-> setlayout (H2 );

// Shapesdockwidget-> setallowedareas (QT: leftdockwidgetarea

// | QT: rightdockwidgetarea );

Adddockwidget (QT: bottomdockwidgetarea, shapesdockwidget1 );

Qdockwidget * shapesdockwidget2 = new qdockwidget (qstring: fromlocal8bit ("playback time "));

Shapesdockwidget2-> setwidget (timelcd );

Shapesdockwidget2-> setmaximumsize (100,100 );

// Shapesdockwidget1-> setlayout (H2 );

// Shapesdockwidget-> setallowedareas (QT: leftdockwidgetarea

// | QT: rightdockwidgetarea );

Adddockwidget (QT: bottomdockwidgetarea, shapesdockwidget2 );

Qdockwidget * shapesdockwidget3 = new qdockwidget (qstring: fromlocal8bit (" "));

Shapesdockwidget3-> setwidget (ui-> widget_4 );

// Shapesdockwidget1-> setlayout (H2 );

// Shapesdockwidget-> setallowedareas (QT: leftdockwidgetarea

// | QT: rightdockwidgetarea );

// Adddockwidget (QT: rightdockwidgetarea, shapesdockwidget3 );

Adddockwidget (QT: bottomdockwidgetarea, shapesdockwidget3 );

Qdockwidget * shapesdockwidget = new qdockwidget (qstring: fromlocal8bit ("volume "));

Shapesdockwidget-> setwidget (volumeslider );

// Shapesdockwidget-> setallowedareas (QT: leftdockwidgetarea

// | QT: rightdockwidgetarea );

Adddockwidget (QT: bottomdockwidgetarea, shapesdockwidget );

UI-> pushbutton_5-> setenabled (false );

UI-> pushbutton_7-> setenabled (false );

// Qaction * at = new qaction ("exit full screen", vwidget );

// Vwidget-> addaction ();

// Vwidget-> setacceptdrops (true );

// At-> setshortcuts (qlist <qkeysequence> () <qkeysequence (QT: key_escape) <qkeysequence (QT: key_mediastop ));

// Connect (at, signal (triggered (), vwidget, slot (exitfullscreen ()));

Qaction * AT1 = new qaction ("exit full screen", vwidget );

Vwidget-> addaction (AT1 );

Vwidget-> setacceptdrops (true );

AT1-> setshortcuts (qlist <qkeysequence> () <qkeysequence (QT: Ctrl + QT: key_return) <qkeysequence (QT: key_mediastop ));

Connect (AT1, signal (triggered (), vwidget, slot (exitfullscreen ()));

Connect (Media, signal (tick (qint64), this, slot (tick (qint64 )));

Readsettings ();

}

Mainwindow ::~ Mainwindow ()

{

Delete UI;

}

Void mainwindow: resizeevent (qresizeevent *)

{

// Qbitmap maskbitmap (width (), height ());

// Maskbitmap. Clear ();

// Qpainter P (& maskbitmap );

// P. setbrush (QT: Black );

// P. drawroundrect (0, 0, width (), height (), 2, 4 );

// P. End ();

// Setmask (maskbitmap );

}

Void mainwindow: mousemoveevent (qmouseevent * event)

{

// If (Event-> buttons () & QT: leftbutton ){

/// Move (Event-> globalpos ()-m_dragposition );

// Move (Event-> globalpos ()-m_dragposition );

// Event-> Accept ();

//}

}

Void mainwindow: mousepressevent (qmouseevent * event)

{

// If (Event-> button () = QT: leftbutton ){

// M_dragposition = event-> globalpos ()-framegeometry (). topleft ();

/// M_dragposition = event-> globalpos ()-framegeometry (). topleft ();

//// UI-> widget-> move (m_dragposition );

// Event-> Accept ();

//}

}

Void mainwindow: on_pushbutton_2_clicked ()

{

This-> close ();

}

Void mainwindow: on_pushbutton_3_clicked ()

{

This-> showminimized ();

}

Bool mainwindow: eventfilter (qobject * OBJ, qevent * event)

{

If (OBJ = UI-> widget ){

If (Event-> type () = qevent: mousebuttonpress ){

Qmouseevent * EV = static_cast <qmouseevent *> (event );

If (ev-> buttons () & QT: leftbutton)

{

M_dragposition = ev-> globalpos ()-framegeometry (). topleft ();

Ev-> Accept ();

}

Return true;

} Else if (Event-> type () = qevent: mousemove ){

Qmouseevent * EV = static_cast <qmouseevent *> (event );

If (ev-> buttons () & QT: leftbutton ){

// Move (Event-> globalpos ()-m_dragposition );

Move (ev-> globalpos ()-m_dragposition );

Ev-> Accept ();

}

}

Else {

Return false;

}

}

Else if (OBJ = W1)

{

If (Event-> type () = qevent: mousebuttonpress ){

Qmouseevent * EV = static_cast <qmouseevent *> (event );

If (ev-> buttons () & QT: leftbutton)

{

Vwidget = new phonon: videowidget (this );

Vwidget-> setaspectratio (phonon: videowidget: aspectratioauto );

Vwidget-> exitfullscreen ();

}

}

}

Else {

// Pass the event on to the parent class

Return qmainwindow: eventfilter (OBJ, event );

}

Return true;

}

Void mainwindow: on_pushbutton_4_clicked ()

{

Qstring filename = qfiledialog: getopenfilename (this, qstring: fromlocal8bit ("file type "),". ", qstring: fromlocal8bit (" question type (*. *)"));

Qdebug () <FILENAME;

Media-> setcurrentsource (phonon: mediasource (filename ));

Media-> play ();

This-> setwindowtitle (filename );

UI-> pushbutton_5-> setenabled (false );

UI-> pushbutton_7-> setenabled (true );

W1-> setfocus ();

// This-> UI-> label-> settext (filename );

}

Void mainwindow: on_pushbutton_8_clicked ()

{

Qmessagebox: Information (this, TR ("about mdiea player "),

TR ("ID: jammy 0.03 "));

}

Void mainwindow: on_pushbutton_clicked ()

{

Vwidget-> enterfullscreen ();

}

Void mainwindow: on_pushbutton_5_clicked ()

{

Media-> play ();

UI-> pushbutton_5-> setenabled (false );

UI-> pushbutton_7-> setenabled (true );

}

Void mainwindow: on_pushbutton_7_clicked ()

{

Media-> pause ();

UI-> pushbutton_7-> setenabled (false );

UI-> pushbutton_5-> setenabled (true );

}

Void mainwindow: on_pushbutton_6_clicked ()

{

// Media-> setcurrentsource (phonon: mediasource (this-> UI-> label-> text ()));

Media-> stop ();

}

Void mainwindow: Tick (qint64 time)

{

Qtime displaytime (0, (Time/60000) % 60,( time/1000) % 60 );

Timelcd-> display (displaytime. tostring ("mm: SS "));

}

Void mainwindow: keypressevent (qkeyevent * K)

{

If (k-> key () = QT: key_space)

{

If (ui-> pushbutton_5-> isenabled () = true)

{

Media-> pause ();

UI-> pushbutton_5-> setenabled (false );

UI-> pushbutton_7-> setenabled (true );

}

Else if (ui-> pushbutton_5-> isenabled () = false)

{

Media-> play ();

UI-> pushbutton_5-> setenabled (true );

UI-> pushbutton_7-> setenabled (false );

}

}

Else if (k-> modifiers () = QT: altmodifier & K-> key () = QT: key_return)

{

Vwidget-> enterfullscreen ();

}

// Else if (k-> modifiers () = QT: shiftmodifier & K-> key () = QT: key_a)

//{

// Vwidget-> enterfullscreen ();

//}

}

Void mainwindow: writesettings ()

{

Qsettings settings ("Software Inc.", "icon Editor ");

Settings. begingroup ("mainwindow ");

Settings. setvalue ("size", size ());

Settings. setvalue ("State", savestate ());

Settings. endgroup ();

}

Void mainwindow: readsettings ()

{

Qsettings settings ("Software Inc.", "icon Editor ");

Settings. begingroup ("mainwindow ");

Resize (settings. Value ("size"). tosize ());

Restorestate (settings. Value ("state"). tobytearray ());

Settings. endgroup ();

}

Void mainwindow: closeevent (qcloseevent * Ex)

{

Int A = qmessagebox: Information (null, qstring: fromlocal8bit ("dialog box"), qstring: fromlocal8bit ("whether to exit"), qstring :: fromlocal8bit ("OK"), qstring: fromlocal8bit ("canceled"), null, 0,-1 );

If (A = 0)

{

Writesettings ();

Ex-> Accept ();

}

Else if (a = 1)

{

Ex-> ignore ();

}

}

**************************************** ************

Mainwindow. h

# Define mainwindow_h

# Include <qmainwindow>

# Include <phonon>

# Include <qwidget>

# Include <qlcdnumber>

Namespace UI {

Class mainwindow;

}

Class mainwindow: Public qmainwindow

{

Q_object

Public:

Explicit mainwindow (qwidget * parent = 0 );

~ Mainwindow ();

Protected:

Phonon: mediaobject * media;

Phonon: videowidget * vwidget;

Phonon: audiooutput * aoutput;

Phonon: volumeslider * volumeslider;

Phonon: seekslider * seekslider;

PRIVATE:

Ui: mainwindow * UI;

Qpoint m_dragposition;

Protected:

Void resizeevent (qresizeevent * event );

Void mousemoveevent (qmouseevent * event );

Void mousepressevent (qmouseevent * event );

Bool eventfilter (qobject * OBJ, qevent * eV );

Qwidget * W1;

Qwidget * W2;

Qwidget * W3;

Qlcdnumber * timelcd;

Private slots:

Void on_pushbutton_6_clicked ();

Void on_pushbutton_7_clicked ();

Void on_pushbutton_5_clicked ();

Void on_pushbutton_clicked ();

Void on_pushbutton_8_clicked ();

Void on_pushbutton_4_clicked ();

Void on_pushbutton_3_clicked ();

Void on_pushbutton_2_clicked ();

Void tick (qint64 time );

Void keypressevent (qkeyevent * k );

Void writesettings ();

Void readsettings ();

Void closeevent (qcloseevent * Ex );

};

# Endif // mainwindow_h

Related Article

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.