Results 1 to 6 of 6

Thread: Problem with phonon in another class

  1. #1
    Join Date
    Apr 2010
    Location
    Rzeszów \ Poland
    Posts
    26
    Thanks
    3
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows Symbian S60

    Default Problem with phonon in another class

    Hello. I want to do a litte music player based on phonon libs.

    I want to make another class with operations like play, stop etc.
    Qt Code:
    1. #include "plik.h"
    2.  
    3. #include <QString>
    4. #include <QDebug>
    5.  
    6. #include <phonon/Global>
    7. #include <phonon/MediaObject>
    8. #include <phonon/AudioOutput>
    9. #include <phonon/MediaSource>
    10. #include <phonon/Path>
    11.  
    12.  
    13. Phonon::MediaObject *mediaObject;
    14. Phonon::AudioOutput *audioOutput;
    15.  
    16.  
    17. Plik::Plik()
    18. {
    19. this->next = NULL;
    20. this->prev = NULL;
    21. }
    22.  
    23. void Plik::setPath(QString path)
    24. {
    25. this->path = path;
    26. return;
    27. }
    28.  
    29. QString Plik::returnPath()
    30. {
    31. return this->path;
    32. }
    33.  
    34. void Plik::playFile()
    35. {
    36. mediaObject = new Phonon::MediaObject(this);
    37. audioOutput = new Phonon::AudioOutput(Phonon::MusicCategory,this);
    38.  
    39. mediaObject->setCurrentSource(Phonon::MediaSource("/home/matulik/test.mp3"));
    40. audioOutput = new Phonon::AudioOutput(Phonon::MusicCategory,this);
    41. Phonon::Path path = Phonon::createPath(mediaObject,audioOutput);
    42.  
    43. mediaObject->setTickInterval(1000);
    44. audioOutput->setVolume(100);
    45. audioOutput->setMuted(FALSE);
    46. mediaObject->play();
    47.  
    48. }
    To copy to clipboard, switch view to plain text mode 

    And in mainwindow:
    Qt Code:
    1. Plik p1;
    2. p1.playFile();
    To copy to clipboard, switch view to plain text mode 

    And this doesnt work.

    I dont know where is the problem, becouse the same source code coping to mainwindow works..

    Qt Code:
    1. #include "odplayer.h"
    2. #include "ui_odplayer.h"
    3. #include "plik.h"
    4.  
    5. #include <QString>
    6. #include <QDebug>
    7.  
    8. #include <phonon/Global>
    9. #include <phonon/MediaObject>
    10. #include <phonon/AudioOutput>
    11. #include <phonon/MediaSource>
    12. #include <phonon/Path>
    13.  
    14.  
    15. Phonon::MediaObject *mediaObject;
    16. Phonon::AudioOutput *audioOutput;
    17.  
    18.  
    19. odplayer::odplayer(QWidget *parent) :
    20. QMainWindow(parent),
    21. ui(new Ui::odplayer)
    22. {
    23. ui->setupUi(this);
    24.  
    25. mediaObject = new Phonon::MediaObject(this);
    26. audioOutput = new Phonon::AudioOutput(Phonon::MusicCategory,this);
    27.  
    28. mediaObject->setCurrentSource(Phonon::MediaSource("/home/matulik/test.mp3"));
    29. audioOutput = new Phonon::AudioOutput(Phonon::MusicCategory,this);
    30. Phonon::Path path = Phonon::createPath(mediaObject,audioOutput);
    31.  
    32. mediaObject->setTickInterval(1000);
    33. audioOutput->setVolume(100);
    34. audioOutput->setMuted(FALSE);
    35. mediaObject->play();
    36. }
    37.  
    38. odplayer::~odplayer()
    39. {
    40. delete ui;
    41. }
    To copy to clipboard, switch view to plain text mode 

    Someone can help?

  2. #2
    Join Date
    Sep 2011
    Posts
    1,241
    Thanks
    3
    Thanked 127 Times in 126 Posts
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: Problem with phonon in another class

    In this code, what is wrong?
    Qt Code:
    1. void func()
    2. {
    3. Plik p1;
    4. p1.playFile();
    5. }
    To copy to clipboard, switch view to plain text mode 


    fyi:
    posting code like this
    Qt Code:
    1. Plik p1;
    2. p1.playFile();
    To copy to clipboard, switch view to plain text mode 
    is not helpful at all because there is no context, e.g. class + method name
    If you have a problem, CUT and PASTE your code. Do not retype or simplify it. Give a COMPLETE and COMPILABLE example of your problem. Otherwise we are all guessing the problem from a fabrication where relevant details are often missing.

  3. #3
    Join Date
    Apr 2010
    Location
    Rzeszów \ Poland
    Posts
    26
    Thanks
    3
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows Symbian S60

    Default Re: Problem with phonon in another class

    Its like this:

    Qt Code:
    1. #include "odplayer.h"
    2. #include "ui_odplayer.h"
    3. #include "plik.h"
    4.  
    5. #include <QString>
    6. #include <QDebug>
    7.  
    8. #include <phonon/Global>
    9. #include <phonon/MediaObject>
    10. #include <phonon/AudioOutput>
    11. #include <phonon/MediaSource>
    12. #include <phonon/Path>
    13.  
    14.  
    15. Phonon::MediaObject *mediaObject;
    16. Phonon::AudioOutput *audioOutput;
    17.  
    18.  
    19. odplayer::odplayer(QWidget *parent) :
    20. QMainWindow(parent),
    21. ui(new Ui::odplayer)
    22. {
    23. ui->setupUi(this);
    24. Plik p1;
    25. p1.playFile();
    26. }
    27.  
    28. odplayer::~odplayer()
    29. {
    30. delete ui;
    31. }
    To copy to clipboard, switch view to plain text mode 

  4. #4
    Join Date
    Sep 2011
    Posts
    1,241
    Thanks
    3
    Thanked 127 Times in 126 Posts
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: Problem with phonon in another class

    yeah, now tell me what is wrong with this
    Qt Code:
    1. odplayer::odplayer(QWidget *parent) :
    2. QMainWindow(parent),
    3. ui(new Ui::odplayer)
    4. {
    5. ui->setupUi(this);
    6. Plik p1;
    7. p1.playFile();
    8. }
    To copy to clipboard, switch view to plain text mode 
    Hint: It's a c++ 'thing'.
    If you have a problem, CUT and PASTE your code. Do not retype or simplify it. Give a COMPLETE and COMPILABLE example of your problem. Otherwise we are all guessing the problem from a fabrication where relevant details are often missing.

  5. The following user says thank you to amleto for this useful post:

    matulik (2nd December 2012)

  6. #5
    Join Date
    Apr 2010
    Location
    Rzeszów \ Poland
    Posts
    26
    Thanks
    3
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows Symbian S60

    Default Re: Problem with phonon in another class

    Ok, I know where is problem:
    Qt Code:
    1. File* f1 = new File;
    2. f1->setPath("/home/matulik/test.mp3");
    3. qDebug()<<f1->returnPath();
    4. f1->playFile();
    To copy to clipboard, switch view to plain text mode 

    Thanks very much for hint

  7. #6
    Join Date
    Sep 2011
    Posts
    1,241
    Thanks
    3
    Thanked 127 Times in 126 Posts
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: Problem with phonon in another class

    what's a `File`? I haven't seen that in your previous code. And what did I just say about posting code with no context?

    By the way, you now have a memory leak.
    If you have a problem, CUT and PASTE your code. Do not retype or simplify it. Give a COMPLETE and COMPILABLE example of your problem. Otherwise we are all guessing the problem from a fabrication where relevant details are often missing.

Similar Threads

  1. Mac Qt SDK Phonon problem
    By ahmdsd_ostora in forum Qt Programming
    Replies: 0
    Last Post: 11th April 2012, 10:49
  2. problem with phonon
    By franco.amato in forum Qt Programming
    Replies: 3
    Last Post: 17th March 2011, 22:53
  3. Replies: 7
    Last Post: 2nd September 2010, 20:42
  4. Problem using Phonon
    By Sismetic in forum Newbie
    Replies: 1
    Last Post: 1st September 2010, 15:33
  5. problem with phonon
    By mismael85 in forum Qt Programming
    Replies: 2
    Last Post: 30th January 2010, 21:25

Tags for this Thread

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Digia, Qt and their respective logos are trademarks of Digia Plc in Finland and/or other countries worldwide.