0

My primary objective is to send a mp3 file over network using QDataStream, QTcpServer and QTcpSocket. But I have broken this task to smaller pieces. At first I need to get the mp3 file to the correct format so that It can be "fed" to the data stream.

How am I supposed to accomplish this? I figured it would be the easiest to use Phonon? But the MediaObject doesnt seem to be offering some sort of getData method.

Any help on how am I supposed to do that would be much appreciated. If needed I can explain more about this.

Majster
  • 3,611
  • 5
  • 38
  • 60

1 Answers1

0

There is no "correct format". Also, your problem is not MP3-specific. You do the same for all files, regardless of what kind of data they contain. You open the file, read bytes from it and send those bytes until there's nothing left to send.

You don't need Phonon or anything MP3-related. You only need to open the file and read bytes from it. You then write those bytes to the socket using the write() function of your QTcpSocket object. You don't even need a QDataStream, since you're only dealing with data that you don't need to parse.

Nikos C.
  • 50,738
  • 9
  • 71
  • 96
  • Yes, indeed. The write method is familiar. How do i read the file and send it over? – Majster Nov 30 '12 at 16:02
  • @Majster Same way you read any file. Create a QFile for it. Whatever you get from QFile::read(), you send to QTcpSocket::write(). – Nikos C. Nov 30 '12 at 16:14
  • Well, I have tried that. At first im trying to read the file and write the same file back to a new named file. No luck with my approach. Where can i paste the code since it is not a part of my question? – Majster Nov 30 '12 at 16:32
  • @Majster Why would you write a new file? You read data from the file, and write that data to the socket. QFile::read() gives you a QByteArray, and QTcpSocket::write() can write that QByteArray. Or you can use the `char*` overloads. I don't see how writing a new file plays into this. – Nikos C. Nov 30 '12 at 16:40
  • Yes, I know. It was just a test. I am doing it step by step. Will try your approach now and see if the client accepts the data. – Majster Nov 30 '12 at 21:23