mirror of https://github.com/qt/qt3d.git
Fix audio-visualizer example
Pick-to: 6.2 6.4 Fixes: QTCREATORBUG-27852 Change-Id: Icc10aa51f54a7ff19dcff2349048b436f273d6bf Reviewed-by: Janne Koskinen <janne.p.koskinen@qt.io> Reviewed-by: Antti Määttä <antti.maatta@qt.io>
This commit is contained in:
parent
e06bccdc93
commit
be9ccff07d
|
|
@ -10,9 +10,10 @@ Entity {
|
|||
id: sceneRoot
|
||||
property int barRotationTimeMs: 1
|
||||
property int numberOfBars: 1
|
||||
property string animationState: "stopped"
|
||||
property string animationState
|
||||
property real titleStartAngle: 95
|
||||
property real titleStopAngle: 5
|
||||
property bool started: false
|
||||
|
||||
onAnimationStateChanged: {
|
||||
if (animationState == "playing") {
|
||||
|
|
@ -73,6 +74,7 @@ Entity {
|
|||
progressTransformAnimation.duration = mediaPlayer.duration
|
||||
mainview.state = "playing"
|
||||
progressTransformAnimation.start()
|
||||
started = true
|
||||
}
|
||||
|
||||
//![0]
|
||||
|
|
|
|||
|
|
@ -10,6 +10,7 @@
|
|||
|
||||
int main(int argc, char* argv[])
|
||||
{
|
||||
qputenv("QML_XHR_ALLOW_FILE_READ", "1");
|
||||
#ifdef Q_OS_ANDROID
|
||||
QGuiApplication::setAttribute(Qt::AA_EnableHighDpiScaling);
|
||||
#endif
|
||||
|
|
|
|||
|
|
@ -1,10 +1,10 @@
|
|||
// Copyright (C) 2017 The Qt Company Ltd.
|
||||
// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR BSD-3-Clause
|
||||
|
||||
import QtQuick 2.0
|
||||
import QtQuick.Scene3D 2.0
|
||||
import QtQuick.Layouts 1.2
|
||||
import QtMultimedia 5.0
|
||||
import QtQuick
|
||||
import QtQuick.Scene3D
|
||||
import QtQuick.Layouts
|
||||
import QtMultimedia
|
||||
|
||||
Item {
|
||||
id: mainview
|
||||
|
|
@ -70,30 +70,25 @@ Item {
|
|||
//![0]
|
||||
MediaPlayer {
|
||||
id: mediaPlayer
|
||||
autoPlay: true
|
||||
volume: 0.5
|
||||
source: "qrc:/music/tiltshifted_lost_neon_sun.mp3"
|
||||
audioOutput: AudioOutput {}
|
||||
//![0]
|
||||
|
||||
onStatusChanged: {
|
||||
if (status == MediaPlayer.EndOfMedia) //{
|
||||
state = "stopped"
|
||||
}
|
||||
|
||||
onError: console.error("error with audio " + mediaPlayer.error)
|
||||
|
||||
onDurationChanged: {
|
||||
// Load the pre-calculated magnitude data for the visualizer
|
||||
var request = new XMLHttpRequest()
|
||||
request.responseType = 'arraybuffer'
|
||||
request.onreadystatechange = function() {
|
||||
onMediaStatusChanged: {
|
||||
if (mediaStatus == MediaPlayer.EndOfMedia) {
|
||||
mainview.state = "stopped"
|
||||
} else if (mediaStatus == MediaPlayer.LoadedMedia && !visualizer.started) {
|
||||
// Load the pre-calculated magnitude data for the visualizer
|
||||
var request = new XMLHttpRequest()
|
||||
request.responseType = 'arraybuffer'
|
||||
request.onreadystatechange = function() {
|
||||
if (request.readyState === XMLHttpRequest.DONE) {
|
||||
if (request.status == 200 || request.status == 0) {
|
||||
var arrayBuffer = request.response
|
||||
if (arrayBuffer) {
|
||||
magnitudeArray = new Uint16Array(arrayBuffer)
|
||||
visualizer.startVisualization()
|
||||
}
|
||||
}
|
||||
} else {
|
||||
console.warn("Couldn't load magnitude data for bars.")
|
||||
}
|
||||
|
|
@ -101,10 +96,13 @@ Item {
|
|||
}
|
||||
};
|
||||
|
||||
request.open('GET', magnitudeDataSourceFile, true)
|
||||
request.send(null)
|
||||
request.open('GET', magnitudeDataSourceFile, true)
|
||||
request.send(null)
|
||||
}
|
||||
}
|
||||
|
||||
onErrorStringChanged: console.error("error with audio " + errorString)
|
||||
|
||||
function getNextAudioLevel(offsetMs) {
|
||||
if (magnitudeArray === null)
|
||||
return 0.0;
|
||||
|
|
|
|||
Loading…
Reference in New Issue