【问题标题】:Soundcloud mp3 not streaming through Chrome iphone appSoundcloud mp3 未通过 Chrome iphone 应用程序流式传输
【发布时间】:2015-06-20 19:41:36
【问题描述】:

我有一个响应式音乐网络应用程序,允许移动使用。我无法让 soundcloud 流在 iphone 上的 chrome 或 safari 浏览器中运行。

歌曲加载(加载曲目名称)但它只是像这样坐在那里:

我已经用我的客户端 ID ({"http_mp3_128_url":"https://cf-media.sndcdn.com/u8ouac3FqckU.128.mp3?) 测试了这首歌确实是一首 mp3。

什么可能导致歌曲无法在移动浏览器中播放?

支持它的代码是这样的:

<i class="fa fa-play falist" ng-click="player.play(show, $index)" ng-show="$index != trackPlayingIndex"></i>
            <i class="fa fa-pause falist" ng-click="player.pause(show, $index)" ng-show="$index == trackPlayingIndex"></i></span>

控制器/服务:

 SC.stream(track.properties.stream_url, function(sound){

          if (playingSound) {
           playingSound.stop();
         }

          sound.play({
            whileplaying: function () {
              player.duration = Math.floor(this.durationEstimate / 1000);
              player.position = Math.floor(this.position / 1000);
              player.progress = (this.position / this.durationEstimate) * 100;
              $rootScope.$broadcast('statusChanged', true);
            },
            onfinish: function () {
              $rootScope.$broadcast('finished');
            }
          });

它在网络浏览器中运行良好,所以我必须为移动浏览器缺少一些东西。

【问题讨论】:

    标签: ios iphone audio soundcloud soundmanager2


    【解决方案1】:

    要在移动设备上播放音频/视频,您需要来自用户的直接、物理和同步交互。 SC.stream() 函数是异步的,因此打破了播放要求之一。

    根据您的应用程序的工作方式,有几种糟糕的方法可以解决此问题。如果您知道页面上应该播放的所有歌曲,您可以在页面加载时对每首歌曲调用 SC.stream(),然后仅在用户实际按下播放按钮时在 sound 实例上调用 .play()

    如果您不知道应该播放的所有歌曲,那么您还有两个更糟糕的选择。首先,我相信您可以将 jQuery ajax 选项传递给SC.stream()SC.get(),这将允许您通过提供以下选项{ async: false } 来发出请求同步 *颤抖*。

    最后一个选项是在您的SC.stream() 回调函数中为'ontouchstart' 事件在整个主体 上设置一个事件侦听器。然后,该事件侦听器将触发对 sound.play() 本身的调用。这意味着用户必须先按下播放按钮,然后在触发SC.stream 回调后触摸页面上的任意位置(甚至滚动)。大多数用户甚至都没有意识到这是一项要求,因为滚动在移动设备上是如此普遍。

    【讨论】:

    • 非常感谢。我最终完成了第一个工作。我希望 Soundcloud 不会生气,我在 ping sc.stream 这么多,但这确实使它适用于移动设备。 // work around for mobile streaming problem angular.forEach($scope.filteredShows,function(value,index){ SC.stream(value.properties.stream_url); })
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2015-04-10
    • 2016-12-21
    • 1970-01-01
    • 2012-01-20
    相关资源
    最近更新 更多