Find the Best Demos and Examples

Check out this quick tour to find the best demos and examples for you, and to see how the Felgo SDK can help you to develop your next app or game!

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.