1

Web サイトの音楽ページ内で、SoundCloud API から取得したお気に入りの曲を再生する音楽コンポーネントがあります。

{{soundcloud-player favorite=currentFavorite sound=currentFavoriteObject position=currentFavoritePosition isPlaying=isPlaying isBuffering=isBuffering}}

問題は、曲を再生してウェブサイトのページ(ルート)を変更すると、曲が再生され続けるため 、ページisPlaying falseの音楽を変更するたびに設定する必要がrouteあることです。

それを達成するにはさまざまな方法があることがわかりますが、私の場合はわかりません

ミが試みる

別のコントローラーから

needs:'player',
desactivateIsplaying: function(){
    var controller = this.get('controllers.player');
    controller.set('isPlaying', false);
}

または別のルートから

desactivateIsPlaying: function(){
    var controller = this.controllerFor('player');
    controller.set('isPlaying', false);
}

設定できない 2 つの関数のいずれかでisPlaying false、ルート アクションについても言及されていwillTransitionますが、どのように使用できますか? それを行うより良い方法はありますか?必要に応じて、シナリオをよりよく再現するためにひねりを加えることができます

4

1 に答える 1

8

ルートで使用willTransitionするのは良いオプションです。

music/route.js

import Ember from 'ember';

const { Route } = Ember;

export default Route.extend({
  actions: {
    willTransition() {
      this.controller.set('isPlaying', false);
    }
  }
});
于 2016-02-22T00:49:03.593 に答える