4 Nisan 2017 Salı

3 Nisan 2017 Pazartesi

QT- QVİDEO PLAYER

videoplayer.pro

#-------------------------------------------------
#
# Project created by QtCreator 2017-04-03T15:39:03
#
#-------------------------------------------------

QT       += core gui multimedia multimediawidgets



greaterThan(QT_MAJOR_VERSION, 4): QT += widgets

TARGET = videoplayer
TEMPLATE = app

# The following define makes your compiler emit warnings if you use
# any feature of Qt which as been marked as deprecated (the exact warnings
# depend on your compiler). Please consult the documentation of the
# deprecated API in order to know how to port your code away from it.
DEFINES += QT_DEPRECATED_WARNINGS

# You can also make your code fail to compile if you use deprecated APIs.
# In order to do so, uncomment the following line.
# You can also select to disable deprecated APIs only up to a certain version of Qt.
#DEFINES += QT_DISABLE_DEPRECATED_BEFORE=0x060000    # disables all the APIs deprecated before Qt 6.0.0


SOURCES += main.cpp\
        dialog.cpp

HEADERS  += dialog.h

FORMS    += dialog.ui



--------------------------------------------------------------------

dialog.h

#ifndef DIALOG_H
#define DIALOG_H

#include < QDialog>

namespace Ui {
class Dialog;
}

class Dialog : public QDialog
{
    Q_OBJECT

public:
    explicit Dialog(QWidget *parent = 0);
    ~Dialog();

private:
    Ui::Dialog *ui;
};

#endif // DIALOG_H

------------------------------------------------------------------------------

dialog.cpp


#include "dialog.h"
#include "ui_dialog.h"

Dialog::Dialog(QWidget *parent) :
    QDialog(parent),
    ui(new Ui::Dialog)
{
    ui- > ;setupUi(this);
}

Dialog::~Dialog()
{
    delete ui;
}

----------------------------------------------------------------------------
main.cpp

#include "dialog.h"
#include < QApplication>
#include< QMediaPlayer>
#include< QVideoWidget>
#include< QDebug>
int main(int argc, char *argv[])
{
    QApplication a(argc, argv);
    // Dialog w;
    // w.show();
   QMediaPlayer* player = new QMediaPlayer;
   QVideoWidget* vw = new QVideoWidget;
   player->setVideoOutput(vw);
   player->setMedia(QUrl::fromLocalFile("//C://Users//dtsis//Desktop//vi.mpg"));
   vw->setGeometry(100,100,300,400);
   vw->show();
   player->play();
   qDebug() << player->state();

    return a.exec();
}
Share:

QT- QMEDİAPLAYER

MyPlayer.pro

#-------------------------------------------------
#
# Project created by QtCreator 2017-04-03T14:07:12
#
#-------------------------------------------------

QT       += core gui multimedia

greaterThan(QT_MAJOR_VERSION, 4): QT += widgets

TARGET = MyPlayer
TEMPLATE = app

# The following define makes your compiler emit warnings if you use
# any feature of Qt which as been marked as deprecated (the exact warnings
# depend on your compiler). Please consult the documentation of the
# deprecated API in order to know how to port your code away from it.
DEFINES += QT_DEPRECATED_WARNINGS

# You can also make your code fail to compile if you use deprecated APIs.
# In order to do so, uncomment the following line.
# You can also select to disable deprecated APIs only up to a certain version of Qt.
#DEFINES += QT_DISABLE_DEPRECATED_BEFORE=0x060000    # disables all the APIs deprecated before Qt 6.0.0


SOURCES += main.cpp\
        dialog.cpp

HEADERS  += dialog.h

FORMS    += dialog.ui




----------------------------------------------------------------------

dialog.h


#ifndef DIALOG_H
#define DIALOG_H

#include < QDialog>
#include< QMediaPlayer>
#include< QDebug>
namespace Ui {
class Dialog;
}

class Dialog : public QDialog
{
    Q_OBJECT

public:
    explicit Dialog(QWidget *parent = 0);
    ~Dialog();

private slots:
    void on_sliderProgress_sliderMoved(int position);

    void on_sliderVolume_sliderMoved(int position);

    void on_pushButton_clicked();

    void on_pushButton_2_clicked();

    void on_durationChanged(quint64 position);

     void on_positionChanged(quint64 position);

private:
    Ui::Dialog *ui;

    QMediaPlayer* player;
};

#endif // DIALOG_H


-------------------------------------------------------------

dialog.cpp

#include " dialog.h"
#include " ui_dialog.h"

Dialog::Dialog(QWidget *parent) :
    QDialog(parent),
    ui(new Ui::Dialog)
{
    ui->setupUi(this);
    player = new QMediaPlayer(this);


    connect(player,&QMediaPlayer::positionChanged,this,&Dialog::on_positionChanged);
    connect(player,&QMediaPlayer::durationChanged,this,&Dialog::on_durationChanged);
}

Dialog::~Dialog()
{
    delete ui;
}

void Dialog::on_sliderProgress_sliderMoved(int position)
{
  player->setPosition(position);
}

void Dialog::on_sliderVolume_sliderMoved(int position)
{
    player->setVolume(position);
}

void Dialog::on_pushButton_clicked()
{


    // Load File

    player->setMedia(QUrl::fromLocalFile("//C://Users/dtsis//Desktop//se.mp3"));
    player->play();
    qDebug() < < player->errorString();




}

void Dialog::on_pushButton_2_clicked()
{
   player->stop();
}

void Dialog::on_durationChanged(quint64 position)
{
   ui->sliderProgress->setMaximum(position);
}

void Dialog::on_positionChanged(quint64 position)
{

    ui->sliderProgress->setValue(position);
}


----------------------------------------------------------

main.cpp


#include "dialog.h"
#include < QApplication>

int main(int argc, char *argv[])
{
    QApplication a(argc, argv);
    Dialog w;
    w.show();

    return a.exec();
}

----------------------------------------------------------------

Share:

QUDP SOCKET

myudp.h


#ifndef MYUDP_H
#define MYUDP_H
#include < QObject>
#include< QUdpSocket>
class MyUDP : public QObject
{
    Q_OBJECT
public:
    explicit MyUDP(QObject *paretnt = 0);
    void SayHello();
signals:
public slots:
    void readyRead();
private:
    QUdpSocket *socket;
};

#endif // MYUDP_H



-------------------------------------------------------
 main.cpp


#include 
#include "myudp.h"
int main(int argc, char *argv[])
{
    QCoreApplication a(argc, argv);
    MyUDP server;
    MyUDP client;
    client.SayHello();
    client.SayHello();
    return a.exec();
}


---------------------------------------------------------
myudp.cpp


#include " myudp.h"
MyUDP::MyUDP(QObject *parent):
    QObject(parent)
{


    socket = new QUdpSocket(this);
    socket->bind(QHostAddress::Any,1234);
    connect(socket,SIGNAL(readyRead()),this,SLOT(readyRead()));

}
void MyUDP::SayHello()
{
    QByteArray Data;
    Data.append("Hello from UDP ");
    socket->writeDatagram(Data,QHostAddress::LocalHost,1234);
}
void MyUDP::readyRead()
{
    QByteArray Buffer;
    Buffer.resize(socket->pendingDatagramSize());
    QHostAddress sender;
    quint16 senderPort;
    socket->readDatagram(Buffer.data(),Buffer.size(),&sender,&senderPort);
    qDebug() < < "Message From : " << sender.toString();
    qDebug() < < "Message Port : " << senderPort;
    qDebug() < < "Message : " << Buffer << "\n\n\n";

}



Share: