【问题标题】:stop sounds after going back to the previous tab返回上一个选项卡后停止声音
【发布时间】:2015-03-29 15:31:32
【问题描述】:

我有一个简单的选项卡式应用程序,用户可以在其中单击一个按钮,然后在显示图片和播放声音的活动选项卡中加载一个视图。 但是,如果用户点击后退按钮,声音不会停止播放。

当我转到上一个视图时,如何让声音停止? 提前致谢!

我的 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);
}

我的 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();

【问题讨论】:

    标签: titanium titanium-mobile titanium-alloy


    【解决方案1】:

    我假设您以 Android 为目标,并且每个合金控制器都代表一个窗口。

    您需要将allowBackground 设置为true 以在Window 所属的Activity 因为Window 关闭而停止时允许音频继续播放。

    http://docs.appcelerator.com/titanium/latest/#!/api/Titanium.Media.AudioPlayer-property-allowBackground

    【讨论】:

    • 感谢您的回复 Fokke,我的目标是 iOS 和 Android。两种平台都有解决方案吗?
    【解决方案2】:

    我是这样解决的:

        $.itemView.addEventListener('close', windowClosed);
        function windowClosed() {
          sound.stop();
        }
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多