Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. Mobile and Embedded
  4. [Android] Audio duration = -1 when play a mp3 audio on website

[Android] Audio duration = -1 when play a mp3 audio on website

Scheduled Pinned Locked Moved Unsolved Mobile and Embedded
1 Posts 1 Posters 243 Views
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • Quang PhuQ Offline
    Quang PhuQ Offline
    Quang Phu
    wrote on last edited by Quang Phu
    #1

    Hi,

    I am facing an issue with mp3 duration, it doesn't work well on android. This is my sample code:

    import QtQuick 2.14
    import QtQuick.Window 2.14
    import QtMultimedia 5.14
    
    Window {
        visible: true
        width: 640
        height: 480
        title: qsTr("Hello World")
        Rectangle {
            anchors.fill: parent
            color: "lightblue"
            Text {
                text: "Click Me!";
                font.pointSize: 24;
                width: 150; height: 50;
    
                Audio {
                    id: playMusic
                    source: "https://phubq.com/upload/EA/toeic_practice/part1/toeic_practice_p1_s10_0.mp3"
                    onPlaybackStateChanged: {
                        console.log("Current status: " + playMusic.playbackState)
                        console.log("Duration: " + playMusic.duration)
                    }
                }
                MouseArea {
                    id: playArea
                    anchors.fill: parent
                    onPressed:  { playMusic.play() }
                }
            }
        }
    }
    

    This is output by os:
    Desktop:

    qml: Current status: 1
    qml: Duration: 0
    qml: Current status: 0
    qml: Duration: 17604
    

    Android:

    D libMP3Example_x86.so: qml: Current status: 1
    D libMP3Example_x86.so: qml: Duration: -1
    D libMP3Example_x86.so: qml: Current status: 0
    D libMP3Example_x86.so: qml: Duration: -1
    

    I don't know why on Android, that duration is -1. In my project, I need correct value to use for Slider.
    Btw, I tested on iOS, and it worked well, then it seems this happens only in android system.
    It also works well if I use mp3 file as resource instead play online mp3.
    This is my system info:

    Qt5.14.1
    Android studio: 3.5.2
    NDK: r20b
    

    Any one have solution for this or met this before?

    1 Reply Last reply
    0

    • Login

    • Login or register to search.
    • First post
      Last post
    0
    • Categories
    • Recent
    • Tags
    • Popular
    • Users
    • Groups
    • Search
    • Get Qt Extensions
    • Unsolved