Forums

OverviewFelgo 2 Support (Qt 5) › A little help with qml audio

Viewing 2 posts - 1 through 2 (of 2 total)
  • Author
    Posts
  • #22673

    jrrobles79

    This is more a question about QML but I haven’t been able to fixed. I added some music to my app and created the next component to add a fade music effect, but I haven’t been able to make it work correctly, the problem is that for some reason the NumberAnimation starts automatic when I call play() method on the audio and obviously the music stops almost immeadiate.  I tryed to pause the animation on the component onCompleted event, but then the music don’t play

     

    MyAudioComponent

    Audio {
    
        id: auRoot;
        volume:1.0;
        
        NumberAnimation on volume{
            id:audiofadeout;
            from:1;
            to: 0;
            duration:1000;
            onStopped: resetAudio();
            onStarted: console.log("play fadeout")
        }
    
        Component.onCompleted: audiofadeout.pause();
    
        function isPlaying(){
            if(auRoot.playbackState === Audio.PlayingState )
                {
                    return true;
                }
            return false;
        }
    
        function fadeSound(){
            audiofadeout.resume();
        }
    
        function resetAudio(){
            auRoot.stop();
            auRoot.volume=1.0;
        }
    }

     

    and I used like:

     

    Page{
    
     MyAudioComponent {
               id: auCountDown;
               source: "music1.mp3"
               loops: Audio.Infinite
             }
        
        onAppeared:{   
            auCountDown.play();
        }
    
     onDisappeared: {
    
          auCountDown.fadeSound();
        }
    
    
    
    }

     

    Any ideas?

     

     

    #22674

    jrrobles79

    If someone need it, I fix it like this:

    Audio {
    
        id: auRoot;
        volume:1.0;
        property bool fadeOutCompleted: false;
        NumberAnimation on volume{
            id:audiofadeout;
            from:1;
            to: 0;
            duration:1000;
            onStarted: console.log("play fadeout");
            onStopped: {
                fadeOutCompleted=true;
                resetAudio();
            }
    
        }
    
        Component.onCompleted: audiofadeout.pause();
    
        function isPlaying(){
            if(auRoot.playbackState === Audio.PlayingState )
                {
                    return true;
                }
            return false;
        }
    
        function fadeSound(){
            if(fadeOutCompleted){
                audiofadeout.restart();
            }else{
                 audiofadeout.resume();
            }
        }
    
        function resetAudio(){
            auRoot.stop();
            auRoot.volume=1.0;
        }
    }

     

Viewing 2 posts - 1 through 2 (of 2 total)

RSS feed for this thread

You must be logged in to reply to this topic.

Voted #1 for:

  • Easiest to learn
  • Most time saving
  • Best support

Develop Cross-Platform Apps and Games 50% Faster!

  • Voted the best supported, most time-saving and easiest to learn cross-platform development tool
  • Based on the Qt framework, with native performance and appearance on all platforms including iOS and Android
  • Offers a variety of plugins to monetize, analyze and engage users
FREE!
create apps
create games
cross platform
native performance
3rd party services
game network
multiplayer
level editor
easiest to learn
biggest time saving
best support