import QtQuick 2.0
import Ubuntu.Components 0.1
import QtMultimedia 5.0
Button
{
id: soundButton
property string soundUrl: ""
onPressedChanged:
{
if(pressed)
{
audio.play()
}
else
{
audio.stop()
}
}
Audio
{
id: audio
source:soundButton.soundUrl;
}
}
This comment has been removed by the author.
ReplyDeleteHey Rick,
ReplyDeleteI would do it slightly more QML'ish:
import QtQuick 2.0
import Ubuntu.Components 0.1
import QtMultimedia 5.0
Button {
id: soundButton
property string soundUrl: ""
Audio {
id: audio
source:soundButton.soundUrl;
playbackState: soundButton.pressed ? Audio.PlayingState : Audio.StoppedState
}
}
try to use as little javascript as possible to speed up your QML application.
Thanks Micahel, that is more QMLish. I still have not shaken off my old habits of responding to signals instead of binding to properties. On the other hand, I wonder if my original code might be a bit easier to read?
DeleteBeing the QML newbie that I am, I don't find it hard to read once it's formatted as yours (indent et.al.)
DeleteNice code simplification Micahel!
ReplyDeleteAlthough, be careful not to make people think the app will be any faster that way. Reducing the size of the JavaScript will impact performance positively if this code is called very frequently, for example as part of an animation.
In the case above, it will not make any difference.
Yep, agreed. It doesn't make any real difference here. Its still a good idea to get used to this declarative way of doing things. Its easier to modify the code to add additional states without ending up in endless if/else trees.
ReplyDeleteVery nice and great article it's also helpful information of all us so thanks a lot for sharing us
ReplyDeleteclipping path service