I have a simple tabbed app where the user can click a button and then a view will load in the active tab where a picture is displayed and a sound is being played. However if the user tabs on the back button the sound doesn't stop playing.
How can I make the sound stop when I go to the previous view? Thanks in advance!
My index.js:
function viewSelectedItem() {
var args = { image : 'images/photo/farm/chicken1.jpg', title : 'kip' };
var win = Alloy.createController('viewItem', args).getView();
Alloy.Globals.tabgroup.activeTab.open(win);
}
my viewItem.js
var args = arguments[0] || {};
$.itemImage.image = args.image;
$.itemTextLabel.text = args.title;
var sound = Ti.Media.createSound({
url: 'sounds/farm/chicken1.mp3'
});
sound.play();
I fixed it like this:
$.itemView.addEventListener('close', windowClosed);
function windowClosed() {
sound.stop();
}