Finding the length of a song - c++

I want to find the length of a song in seconds so that I can make a playlist with the M3U format, but I don't know how to get that info from the file. I am using id3lib and also Qt.
I've tried:
ID3_Frame* myFrame = myTag.Find(ID3FID_SONGLEN);
ID3_Frame* myFrame = myTag.Find(ID3FID_TIME);
ID3_Frame* myFrame = myTag.Find(ID3FID_SIZE);
but myFrame was NULL. I tried other parameters and worked, like ID3FID_ALBUM. I really don't know what to try. I didn't find anything in the id3lib API.
I know that Qt can give me that info, but can't I use id3lib?
Later edit: I've read that MediaObject::totalTime() gives me the time only if the song is played but I want that info, regarding that the songs are played or not; I need this info to write it in a file.
LATER EDIT:
I am trying to use Phonon from Qt for the length, but i receive a lot of errors.
#include <Phonon/MediaSource>
#include <Phonon/MediaObject>
#include <iostream>
#include <Qstring>
/* stuff */
Phonon::MediaObject *mediaObject = new Phonon::MediaObject();
QString fileName("D:/melodie.mp3");
mediaObject->setCurrentSource(fileName);
cout << mediaObject->totalTime() << endl;
I get a lot of unresolved external symbol
main.obj:-1: error: LNK2019: unresolved external symbol "__declspec(dllimport) public: __thiscall Phonon::MediaObject::MediaObject(class QObject *)" (_imp??0MediaObject#Phonon##QAE#PAVQObject###Z) referenced in function _main
I am using QCreator, my application is simple, just a window that says hello(it works if i don't use Phonon); i just can't make it run; i've allocated static mediaObject, i've made a MediaSource and tried to pass it, but it doesn't work(here it says that can't covert from MediaSource* to MediaSource &). What could be the problem?

You can use Phonon::MediaObject::totalTime() to get the length of the song in milliseconds.
id3lib does not provide a function to directly find the length of a song because track length is not part of the ID3v1 or ID3v2 "standards". They are merely for tagging. If you're getting a 0 when you try the code in your question, it probably means that those tags haven't been set yet. As noted in the docs, "...the Find() method will return a NULL pointer if no such frame can be found."

Use MediaObject::totalTime after setting correctly the media source

I suggest you to use totalTimeChanged(qint64 newTotalTime) signal. It is more careful way to capture length of the track, because you don't need to manually check state of mediaObject.

Related

SFML : drawing from different files

I'm working on a SFML project that contains several different files and classes. The problem is : in every file, there is some drawing, and the sf::RenderWindow* defined in the main file seems to be out of scope here, therefore I can't link these drawing with the main window. I've tried to redefine sf::RenderWindow in every header files, and it doesn't work as well (a black screen appear and disappear promptly). The error was : Access violation reading location. But when I group everything in one file, things work well but it looks really messy.
I also found this question asked on another forum, and the answers were "using reference and external method", which is a bit vague to me. Any help on this linking problem would be appreciated :(
I think that answer meant something like:
void draw_in_class (sf::RenderWindow* window){
window->draw(...);
}
in class, and then you can use 'draw_in_class' in main:
#include"class.h"
... // Define sf::RenderWindow here
draw_in_class(&window);

SetCursorPos in wxWidgets

I code with visual c++, and i use wxwidget 3.x., Windows 10
I would like to use SetCursorPos (to move my camera, and let the mouse cursor stay in middle of screen), but i got some error message:
canvas.obj : error LNK2019: unresolved external symbol __imp__SetCursorPos#8 referenced in function "public: void __thiscall CanvasFrame::setCursorPos(int,int)" (?setCursorPos#CanvasFrame##QAEXHH#Z)
I m not sure i can use SetCursorPos via wwxwidget, i think wxwidget manage this, but cant find it on google …
Some idea?
My bad …
this->WarpPointer(renderer->GetWidth() / 2, renderer->GetHeight() / 2);
works..
Thanks anyway :)

Symbol does not show up on ArcGIS Map using Qt

I am using Qt together with the ArcGIS api and I want to display a military symbol using the MessageHelper class. Here is my code:
m_map = new EsriRuntimeQt::Map(this);
m_mapGraphicsView = EsriRuntimeQt::MapGraphicsView::create(m_map, this);
setCentralWidget(m_mapGraphicsView);
m_map->setWrapAroundEnabled(false);
QString path = EsriRuntimeQt::ArcGISRuntime::installDirectory();
path.append("/sdk/samples/data");
QDir dataDir(path); // using QDir to convert to correct file separator
QString pathSampleData = dataDir.path() + QDir::separator();
// ArcGIS Online Tiled Basemap Layer
m_tiledServiceLayer = new EsriRuntimeQt::ArcGISTiledMapServiceLayer("http://services.arcgisonline.com/ArcGIS/rest/services/World_Topo_Map/MapServer", this);
m_map->addLayer(m_tiledServiceLayer);
// test message processing
m_msgGroupLayer = new EsriRuntimeQt::MessageGroupLayer(EsriRuntimeQt::SymbolDictionaryType::Mil2525C);
m_map->addLayer(m_msgGroupLayer);
// build message
EsriRuntimeQt::Point pt(0, 0, m_map->spatialReference());
QList<EsriRuntimeQt::Point> controlPoints;
controlPoints.push_back(pt);
EsriRuntimeQt::Message msg = EsriRuntimeQt::MessageHelper::createUpdateMessage(EsriRuntimeQt::SymbolDictionaryType::App6B, "1", "position_report", controlPoints);
// process the message
m_msgGroupLayer->messageProcessor()->processMessage(msg);
I only see the map but no symbol. I am using Qt-Creator 5.7 and the ArcGIS sdk 10.2.6. Am I somthing missing or is something wrong with my point definition? I expect the symbol to see in the middle of the world map as I use the default spatial reference but I don't see anything there.
The layer and the message use 2 different symbol dictionary types - the layer is created with Mil2525C and the message is created with App6B. These should match.

What could be the cause for runtime "can't find linker symbol for virtual table..." error in Qt?

This question was asked in similar ways multiple times, for example at stackoverflow or forum.qt.io or qtcentre.org. The problem is that this error message is so vague that one solution cannot be applied to another scenario. Most of the threads are dead in the middle of the discussion though :-(
So the complete error message that I get in my Qt application is:
can't find linker symbol for virtual table for "OneOfMyClasses" value
found "QString::shared_null" instead
The OneOfMyClasses changes depending on various things, the QString::shared_null stays the same for all errors that I get. Here is a screenshot of my logging console:
Why is the font color pink, so who is printing this message?
Why do I only see this message when I set a breakpoint and step through my code? This message does not appear when simply running the application.
The point where it happens is in this function in the source line right before the current position (yellow arrow):
So according to the message I stepped into m_pStateWidget->insertNavLabel(...) and the error message is printed somewhere in the constructors inside Qt related to the QString class. So I tried the following, which moves the problem away from this code location:
When doing this I get the same error message a few code lines below with another class name in the message, note that the QString::shared_null stays the same.
It appears to me that I have some sort of corrupted memory.
How should I start investigating this issue? I'm afraid to change the code because this might hide the problem as described above.
What's up with the QString::shared_null? I have found that others often see the same in their error messages.
Thank you for any hint or help! :-)
Edit: It's becoming really interesting now. I have stepped into every single function just right before the message is printed and I ended up with these error messages:
at this location:
When I navigate through the call stack in QtCreator the error is printed again and again everytime I select another function in the stack.
Does this mean that the debugger is printing the message and that it is simply too stupid to resolve some sort of vtable stuff for me or does this mean that I have serious trouble going on?
Cause:
Somewhere in your code , you might have overrun the actual memory
Example 1 :
int elmArray[10];
for(int i = 0; i < 20; ++i)
{
elmArray[i] = 0;
}
In the above case, actual array size is 10 but we are assigning values to the index beyond 10.
Example 2:
char* cpyString;
strcpy(cpyString , "TEST");
These scenarios might end up in writing the values into other objects. Mostly could corrupt the virtual table.This gives the above warning.
Fix:
As you know, just correct the code as below.
Example :
int elmArray[10];
for(int i = 0; i < 10; ++i)
{
elmArray[i] = 0;
}
char cpyString[10];
strcpy(cpyString , "TEST");
In your case seems like, you are assigning the QTString::shared_null to some uninitialized string.
There are various threads on different websites where the
can not find linker symbol for virtual table
problem is discussed. Few explain why the problem exists, although some solutions are given to specific examples. Having experienced difficulty with this, I would like to share what I have learned.
First this error message only appeared for Linux builds, it did not show up for Windows builds.
In my case the problem was caused by a second call into a non-reentrant method from the same thread. Once I found the problem, it was easy to fix by using a static busy flag, and simply returning when busy was called a second time. In a nutshell that was the problem and solution. But how did I get into this mess?
Well the non-rentrant method was actually a Qt slot. Since I knew there was a possibility of the second call (actually an emit) being made from the first, the connect was set up with Qt::QueuedConnection. However, I later put up a splash screen QSplashScreen while the function was processing. Little did I realize that QSplashScreen::repaint() called QApplication::processEvents() which dispatched the second offending emit.
So I could have fixed the problem by removing the QSplashScreen and using a QLabel. However, while either works nicely in Windows, neither actually works in Linux, they put up a semi-transparent window and don't paint the contents (even repaint() and or processEvents() doesn't do it). So that is probably a Qt Linux bug, which is another story.

C++ "Unresolved External Symbol" error when using static LPWSTR

Have just started with some Windows programming, and i´m working on a window class. I thougth that it was a good idea to have a static LPWSTR that I could use when I create different windows in my program. Doubt that I will need more when I move on to direct3D but I still want to have the feature, and it seems like it can be good to learn how Windows deals with a program that has multiple windows.
Know I dont really know how Windows uses the WINDCLASS(EX) classname, if there are any advantadges of having more than one class, in that case please tell me.
Well lets talk about my problem. I declare the static LPWSTR (Correct me if i´m wrong but this is a wchar_t*??) here:
class Window
{
public:
//other code removed
static LPWSTR windowClassName;
}
Then a set the variable before I create my first window:
Window::windowClassName = L"WindowClass";
Window window1 = Window(L"Engine Window1");
window1.initialize(hInstance, 100, 100, 1280, 720);
window1.showWindow(cmdShow);
But I get the unresolved externals error. This doesn´t make sense to me, so I can create a static variable in a class, make it public, but I can´t change it? What do I have to do to make this to work? Or is it just so simple that static members cant be set in a method? That I think would be really stuip since I can´t set it´s value during run-time. Can someone please explain this to me?