Results 1 to 2 of 2

Thread: How to get Duration of .Mp3/.Avi file in Qt without using QMediaPlayer

  1. #1
    Join Date
    Feb 2012
    Posts
    24
    Thanks
    4
    Thanked 11 Times in 11 Posts
    Qt products
    Qt4
    Platforms
    Windows

    Post How to get Duration of .Mp3/.Avi file in Qt without using QMediaPlayer

    I have been working on an application where I can traverse the system drives and look for audio/video files, grab the details and display it on QTreeview. I have been successful in displaying file name, type, size etc but DURATION is something which I am not able to do. Here is the code
    Qt Code:
    1. // Displays Files in Detail View on Clicking Drive
    2. void DetailView::on_DriveView_clicked(const QModelIndex &index)
    3. {
    4. int m_count_row = 0;
    5.  
    6. QString sPath = m_SystemModel->fileInfo(index).absoluteFilePath();
    7. m_SystemListViewModel->setRootPath(sPath);
    8. ui->DriveListView->setRootIndex(m_SystemListViewModel->index(sPath));
    9.  
    10. m_SystemModel->setRootPath(QDir::currentPath());
    11. m_SystemModel->setFilter(QDir::NoDotAndDotDot | QDir::AllDirs );
    12. m_SystemListViewModel->setFilter( QDir::Files | QDir::NoDotAndDotDot );
    13.  
    14. QStringList m_list;
    15. QDirIterator dirIt(sPath,QDirIterator::Subdirectories);
    16.  
    17. while (dirIt.hasNext())
    18. {
    19. dirIt.next();
    20. if (QFileInfo(dirIt.filePath()).isFile())
    21. {
    22. if (QFileInfo(dirIt.filePath()).suffix() == "mp3" ||(QFileInfo(dirIt.filePath()).suffix() == "mts" ) ||(QFileInfo(dirIt.filePath()).suffix() == "m2ts" ))
    23. {
    24. m_list << dirIt.filePath();
    25.  
    26. QModelIndex m_index = model->index(m_count_row, 0, QModelIndex());
    27. model->setHeaderData( 0, Qt::Horizontal, "Name" );
    28. model->setHeaderData( 1, Qt::Horizontal, "Type" );
    29. model->setHeaderData( 2, Qt::Horizontal, "Size" );
    30. model->setHeaderData( 3, Qt::Horizontal, "Date Modified" );
    31. model->setHeaderData( 4, Qt::Horizontal, "Duration" );
    32.  
    33. model->setData( m_index, dirIt.fileName(), Qt::DecorationRole );
    34. QStandardItem *itemName = new QStandardItem(dirIt.fileName());
    35. model->setItem(m_count_row, 0, itemName);
    36.  
    37. model->setData( m_index, dirIt.fileInfo().suffix(), Qt::DecorationRole );
    38. QStandardItem *itemExtention = new QStandardItem( dirIt.fileInfo().suffix());
    39. model->setItem(m_count_row, 1, itemExtention);
    40.  
    41. model->setData( m_index, dirIt.fileInfo().size(), Qt::DecorationRole );
    42. float fFileSize = dirIt.fileInfo().size();
    43. float fFileKB = fFileSize / 1024; //kilobyte
    44. float fFileMB = fFileKB / 1024; //megabyte
    45. float fFinalSize = ceilf(fFileMB * 100) / 100;
    46.  
    47. QString sSizeValue = QString::number(fFinalSize);
    48. QStandardItem *itemSize = new QStandardItem(sSizeValue + " MB");
    49. model->setItem(m_count_row, 2, itemSize);
    50.  
    51. ui->DriveListView->setModel(model);
    52. ui->DriveListView->setRootIsDecorated(false);
    53. m_count_row++;
    54. }
    55. }
    56.  
    57. m_SystemListViewModel->setNameFilterDisables(false);
    58. }
    59. }
    To copy to clipboard, switch view to plain text mode 

    I am not sure whether I can get the duration using the above way since I couldnt find any such property. Is their any other way of doing it? I don want to use QMediaPlayer. Any other alternate solution which can help me update my above code with Duration???

  2. The following user says thank you to owais_blore for this useful post:


  3. #2
    Join Date
    Jan 2006
    Location
    Graz, Austria
    Posts
    8,416
    Thanks
    37
    Thanked 1,544 Times in 1,494 Posts
    Qt products
    Qt3 Qt4 Qt5
    Platforms
    Unix/X11 Windows

    Default Re: How to get Duration of .Mp3/.Avi file in Qt without using QMediaPlayer


  4. The following user says thank you to anda_skoa for this useful post:


Similar Threads

  1. How to get video file duration in Qt?
    By newtolinux in forum Qt Programming
    Replies: 2
    Last Post: 26th November 2010, 12:09
  2. how to set duration of a video in a video player in qt
    By qt_user in forum Qt Programming
    Replies: 1
    Last Post: 7th August 2010, 11:51
  3. Replies: 3
    Last Post: 28th March 2009, 16:37
  4. Replies: 3
    Last Post: 25th May 2007, 08:49

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.