Esempio n. 1
0
        public void ShufflePlaylist()
        {
            if (PlayingItemIndex == NoPlayingItemIndex)
            {
                ShuffledPlaylist = new List <QueueItem>(SortedPlaylist);
                Shuffle(ShuffledPlaylist);
            }
            else if (ShuffleMode.Equals(GroupShuffleMode.Sorted))
            {
                // First time shuffle.
                var playingItem = SortedPlaylist[PlayingItemIndex];
                ShuffledPlaylist = new List <QueueItem>(SortedPlaylist);
                ShuffledPlaylist.RemoveAt(PlayingItemIndex);
                Shuffle(ShuffledPlaylist);
                ShuffledPlaylist.Insert(0, playingItem);
                PlayingItemIndex = 0;
            }
            else
            {
                // Re-shuffle playlist.
                var playingItem = ShuffledPlaylist[PlayingItemIndex];
                ShuffledPlaylist.RemoveAt(PlayingItemIndex);
                Shuffle(ShuffledPlaylist);
                ShuffledPlaylist.Insert(0, playingItem);
                PlayingItemIndex = 0;
            }

            ShuffleMode = GroupShuffleMode.Shuffle;
            LastChange  = DateTime.UtcNow;
        }
Esempio n. 2
0
        public void SetPlayerShuffleMode(string playerId, ShuffleMode shuffleMode)
        {
            var value = JsonConvert.SerializeObject(shuffleMode, new Converters.ShuffleModeConverter());

            var request = new SlimJsonRpcRequest(playerId, new object[] { "playlist", "shuffle", value });

            PostJsonRpcRequest(request);
        }
Esempio n. 3
0
        internal void NotifyShuffleMode(ShuffleMode shuffle)
        {
            int ret = Interop.Bluetooth.NotifyShuffleMode((int)shuffle);

            if (ret != (int)BluetoothError.None)
            {
                Log.Error(Globals.LogTag, "Failed to notify shuffle mode to remote device, Error - " + (BluetoothError)ret);
                BluetoothErrorFactory.ThrowBluetoothException(ret);
            }
        }
 /// <summary>
 /// Creates a new <see cref="PartitionTransformation{TElement}"/> from the given input and <see cref="StreamPartitioner{T}"/>.
 /// </summary>
 /// <param name="input">The input <see cref="Transformation{TElement}"/></param>
 /// <param name="partitioner">The <see cref="StreamPartitioner{T}"/></param>
 /// <param name="shuffleMode">The <see cref="ShuffleMode"/></param>
 public PartitionTransformation(
     Transformation <TElement> input,
     StreamPartitioner <TElement> partitioner,
     ShuffleMode shuffleMode)
     : base("Partition", input.OutputType, input.Parallelism)
 {
     Input       = input;
     Partitioner = partitioner;
     ShuffleMode = shuffleMode;
 }
        internal void SetShuffleMode(ShuffleMode mode)
        {
            int ret = Interop.Bluetooth.SetShuffleMode(mode);

            if (ret != (int)BluetoothError.None)
            {
                Log.Error(Globals.LogTag, "Failed to set shuffle mode to " + mode + " - " + (BluetoothError)ret);
                BluetoothErrorFactory.ThrowBluetoothException(ret);
            }
        }
Esempio n. 6
0
 private List <QueueItem> GetPlaylistInternal()
 {
     if (ShuffleMode.Equals(GroupShuffleMode.Shuffle))
     {
         return(ShuffledPlaylist);
     }
     else
     {
         return(SortedPlaylist);
     }
 }
Esempio n. 7
0
 /// <summary>
 /// Notifies the shuffle mode to the remote device.
 /// </summary>
 /// <remarks>
 /// The remote device must be connected.
 /// </remarks>
 /// <param name="mode">The shuffle mode.</param>
 /// <exception cref="NotSupportedException">Thrown when the Bluetooth is not supported.</exception>
 /// <exception cref="InvalidOperationException">Thrown when the Bluetooth is not enabled
 /// or when notifying the shuffle mode state to the remote device fails.</exception>
 /// <since_tizen> 3 </since_tizen>
 public void NotifyShuffleMode(ShuffleMode mode)
 {
     if (BluetoothAdapter.IsBluetoothEnabled && Globals.IsInitialize)
     {
         BluetoothAvrcpImpl.Instance.NotifyShuffleMode(mode);
     }
     else
     {
         BluetoothErrorFactory.ThrowBluetoothException((int)BluetoothError.NotEnabled);
     }
 }
Esempio n. 8
0
 public void ToggleShuffleMode()
 {
     if (ShuffleMode.Equals(GroupShuffleMode.Sorted))
     {
         ShufflePlaylist();
     }
     else
     {
         RestoreSortedPlaylist();
     }
 }
Esempio n. 9
0
        public void Queue(IReadOnlyList <Guid> items)
        {
            var newItems = CreateQueueItemsFromArray(items);

            SortedPlaylist.AddRange(newItems);
            if (ShuffleMode.Equals(GroupShuffleMode.Shuffle))
            {
                ShuffledPlaylist.AddRange(newItems);
            }

            LastChange = DateTime.UtcNow;
        }
Esempio n. 10
0
        public void SetPlaylist(IReadOnlyList <Guid> items)
        {
            SortedPlaylist.Clear();
            ShuffledPlaylist.Clear();

            SortedPlaylist = CreateQueueItemsFromArray(items);
            if (ShuffleMode.Equals(GroupShuffleMode.Shuffle))
            {
                ShuffledPlaylist = new List <QueueItem>(SortedPlaylist);
                Shuffle(ShuffledPlaylist);
            }

            PlayingItemIndex = NoPlayingItemIndex;
            LastChange       = DateTime.UtcNow;
        }
Esempio n. 11
0
 private QueueItem GetPlayingItem()
 {
     if (PlayingItemIndex == NoPlayingItemIndex)
     {
         return(null);
     }
     else if (ShuffleMode.Equals(GroupShuffleMode.Shuffle))
     {
         return(ShuffledPlaylist[PlayingItemIndex]);
     }
     else
     {
         return(SortedPlaylist[PlayingItemIndex]);
     }
 }
Esempio n. 12
0
        private void UpdateActions()
        {
            // Clear out the old options
            foreach (string id in shuffle_modes.Values)
            {
                Remove(String.Format("Shuffle_{0}", id));
            }
            shuffle_modes.Clear();

            var radio_group = new RadioActionEntry [shuffler.RandomModes.Count];
            int i           = 0;

            // Add all the shuffle options
            foreach (var random_by in shuffler.RandomModes)
            {
                string action_name = String.Format("Shuffle_{0}", random_by.Id);
                int    id          = shuffle_modes.Count;
                shuffle_modes[id] = random_by.Id;
                radio_group[i++]  = new RadioActionEntry(
                    action_name, null,
                    random_by.Label, null,
                    random_by.Description,
                    id);
            }

            Add(radio_group, 0, OnActionChanged);

            // Set the icons
            foreach (var random_by in shuffler.RandomModes)
            {
                this[String.Format("Shuffle_{0}", random_by.Id)].IconName = random_by.IconName ?? "media-playlist-shuffle";
            }
            this[shuffle_off_action].StockId = Gtk.Stock.MediaNext;

            var action = this[ConfigIdToActionName(ShuffleMode.Get())];

            if (action is RadioAction)
            {
                Active = (RadioAction)action;
            }
            else
            {
                Active = (RadioAction)this[shuffle_off_action];
            }

            Active.Activate();
            OnChanged();
        }
Esempio n. 13
0
        public StreamEdge(StreamNode sourceVertex, StreamNode targetVertex, int typeNumber,
                          IList <string> selectedNames, StreamPartitioner <object> outputPartitioner, OutputTag <object> outputTag,
                          ShuffleMode shuffleMode)
        {
            SourceId           = sourceVertex.Id;
            TargetId           = targetVertex.Id;
            TypeNumber         = typeNumber;
            SelectedNames      = selectedNames;
            OutputPartitioner  = outputPartitioner;
            OutputTag          = outputTag;
            SourceOperatorName = sourceVertex.OperatorName;
            TargetOperatorName = targetVertex.OperatorName;
            ShuffleMode        = Preconditions.CheckNotNull(shuffleMode);

            EdgeId = sourceVertex + "_" + targetVertex + "_" + typeNumber + "_" + selectedNames + "_" + outputPartitioner;
        }
Esempio n. 14
0
        public void QueueNext(IReadOnlyList <Guid> items)
        {
            var newItems = CreateQueueItemsFromArray(items);

            if (ShuffleMode.Equals(GroupShuffleMode.Shuffle))
            {
                var playingItem            = GetPlayingItem();
                var sortedPlayingItemIndex = SortedPlaylist.IndexOf(playingItem);
                // Append items to sorted and shuffled playlist as they are.
                SortedPlaylist.InsertRange(sortedPlayingItemIndex + 1, newItems);
                ShuffledPlaylist.InsertRange(PlayingItemIndex + 1, newItems);
            }
            else
            {
                SortedPlaylist.InsertRange(PlayingItemIndex + 1, newItems);
            }

            LastChange = DateTime.UtcNow;
        }
Esempio n. 15
0
        private void RegisterShuffleModeChangedEvent()
        {
            Log.Debug(Globals.LogTag, "inside RegisterShuffleModeChangedEvent");
            _shuffleModeChangedCallback = (int shuffle, IntPtr userData) =>
            {
                Log.Debug(Globals.LogTag, "inside RegisterShuffleModeChangedEvent callback");
                if (_shuffleModeChanged != null)
                {
                    ShuffleMode mode = (ShuffleMode)shuffle;
                    _shuffleModeChanged(null, new ShuffleModeChangedeventArgs(mode));
                }
            };
            int ret = Interop.Bluetooth.SetShuffleModeChangedCallback(_shuffleModeChangedCallback, IntPtr.Zero);

            if (ret != (int)BluetoothError.None)
            {
                Log.Debug(Globals.LogTag, "failed inside RegisterShuffleModeChangedEvent");
                Log.Error(Globals.LogTag, "Failed to set shuffle mode changed callback, Error - " + (BluetoothError)ret);
            }
        }
        private void OnShuffleModeChanged(object o, ShuffleModeChangedEventArgs args)
        {
            if (active_action.Value != (int)args.ShuffleMode)
            {
                // This happens only when changing the mode using DBus.
                // In this case we need to locate the action by its value.
                foreach (RadioAction action in this)
                {
                    if (action.Value == (int)args.ShuffleMode)
                    {
                        active_action = action;
                        break;
                    }
                }
            }

            if (saved_action == null)
            {
                ShuffleMode.Set(ActionNameToConfigId(active_action.Name));
            }
            OnChanged();
        }
Esempio n. 17
0
        public void ClearPlaylist(bool clearPlayingItem)
        {
            var playingItem = GetPlayingItem();

            SortedPlaylist.Clear();
            ShuffledPlaylist.Clear();
            LastChange = DateTime.UtcNow;

            if (!clearPlayingItem && playingItem != null)
            {
                SortedPlaylist.Add(playingItem);
                if (ShuffleMode.Equals(GroupShuffleMode.Shuffle))
                {
                    ShuffledPlaylist.Add(playingItem);
                }

                PlayingItemIndex = 0;
            }
            else
            {
                PlayingItemIndex = NoPlayingItemIndex;
            }
        }
Esempio n. 18
0
        private void OnShuffleModeChanged(object o, EventArgs <string> args)
        {
            if (shuffle_modes[active_action.Value] != args.Value)
            {
                // This happens only when changing the mode using DBus.
                // In this case we need to locate the action by its value.
                ThreadAssist.ProxyToMain(delegate {
                    foreach (RadioAction action in this)
                    {
                        if (shuffle_modes[action.Value] == args.Value)
                        {
                            active_action = action;
                            break;
                        }
                    }
                });
            }

            if (saved_action == null)
            {
                ShuffleMode.Set(ActionNameToConfigId(active_action.Name));
            }
            OnChanged();
        }
Esempio n. 19
0
 /// <summary>
 /// Sets the Shuffle mode setting
 /// </summary>
 /// <param name="mode"></param>
 /// <returns></returns>
 public Task SetShuffleModeAsync(ShuffleMode mode)
 {
     return(mediaPlayer.SetPropertyAsync("ShuffleMode", mode.ToString().ToUpper()));
 }
Esempio n. 20
0
 internal ShuffleModeChangedeventArgs(ShuffleMode mode)
 {
     _mode = mode;
 }
Esempio n. 21
0
 private void MediaPlayer_ShuffleModeChanged(object sender, ShuffleMode e)
 {
     ShuffleMode = e;
     OnPropertyChanged(nameof(ShuffleMode));
 }
Esempio n. 22
0
        public async Task <ShuffleMode> SetShuffleMode(ShuffleMode mode = ShuffleMode.ShuffleOn)
        {
            var response = await _channel.SetShuffle((int)mode).ConfigureAwait(false);

            return((ShuffleMode)response.Shuffle);
        }
Esempio n. 23
0
        private async void OnShuffleButtonClick(string playlistId, ShuffleMode shuffleMode, View popup)
        {
            if (_state.Value != State.Waiting && _state.Value != State.Failed)
            {
                return;
            }

            _state.Value = State.LoadingTracks;

            Task <Exception> task = Task <Exception> .Factory.StartNew(() =>
            {
                try
                {
                    // get playlist
                    FullPlaylist playlist =
                        _api.GetPlaylist(playlistId, fields: "id,name,tracks.items(track.uri),tracks.total");

                    if (playlist.Tracks == null)
                    {
                        return(new Exception("Failed to get playlist"));
                    }

                    // get tracks
                    IList <FullTrack> tracks = Enumerable.Range(0, (int)Math.Ceiling(playlist.Tracks.Total / 100F))
                                               .Select(i =>
                                                       _api.GetPlaylistTracks(playlist.Id, fields: "items.track(uri,artists.name)",
                                                                              offset: i * 100))
                                               .SelectMany(group => group.Items.Select(playlistTrack => playlistTrack.Track))
                                               .ToList();

                    if (tracks.Count != playlist.Tracks.Total)
                    {
                        return(new Exception("Failed to get all tracks in playlist"));
                    }

                    // randomize track order
                    if (shuffleMode == ShuffleMode.Shuffle)
                    {
                        tracks.Shuffle();
                    }
                    else if (shuffleMode == ShuffleMode.Restrict)
                    {
                        // get value
                        EditText value = popup.FindViewById <EditText>(Resource.Id.restrict_value);
                        bool res       = int.TryParse(value.Text, out int artistLimit);

                        // check value is valid
                        if (!res || artistLimit < 1)
                        {
                            throw new Exception("Restrict value is not a positive integer");
                        }

                        // save value
                        ISharedPreferencesEditor editor = GetSharedPreferences("SPOTIFY", 0).Edit();
                        editor.PutString("RESTRICT_VALUE", artistLimit.ToString());
                        editor.Commit();

                        tracks = tracks
                                 .GroupBy(track => track.Artists[0].Name)
                                 .SelectMany(artist => artist.ToList().Shuffle().Take(artistLimit))
                                 .ToList()
                                 .Shuffle();
                    }

                    // add tracks
                    string id = _api.GetPrivateProfile().Id;

                    // delete old playlists
                    foreach (SimplePlaylist p in _playlists.Where(p => p.Name == playlist.Name + " " + shuffleMode)
                             .ToList())
                    {
                        ErrorResponse error = _api.UnfollowPlaylist(id, p.Id);
                        if (error.HasError())
                        {
                            return(new Exception("Failed to delete old playlist"));
                        }
                        _playlists.Remove(p);
                    }

                    // create new playlist
                    _state.Value             = State.AddingTracks;
                    FullPlaylist newPlaylist = _api.CreatePlaylist(id, playlist.Name + " " + shuffleMode, false);
                    if (newPlaylist.Id == null)
                    {
                        return(new Exception("Failed to create new playlist"));
                    }


                    _playlists.Add(new SimplePlaylist {
                        Id = newPlaylist.Id, Name = newPlaylist.Name
                    });

                    // add tracks
                    List <ErrorResponse> addResult = Enumerable.Range(0, (int)Math.Ceiling(tracks.Count / 100F)).Select(
                        i =>
                        _api.AddPlaylistTracks(newPlaylist.Id,
                                               tracks.Skip(i * 100).Take(100).Select(track => track.Uri).ToList()))
                                                     .ToList();

                    if (addResult.Any(error => error.HasError()))
                    {
                        return(new Exception("Failed to add all tracks to playlist"));
                    }

                    return(null);
                }
                catch (Exception)
                {
                    return(new Exception("Unknown error has occured"));
                }
            });

            await task.ContinueWith(errorTask =>
            {
                if (errorTask.Result == null)
                {
                    Log.Debug("ShuffleResult", "Shuffle succeeded");

                    _state.Value = State.Waiting;
                }
                else
                {
                    Log.Debug("ShuffleResult", $"Shuffle failed: {errorTask.Result}");
                    _lastError = errorTask.Result.Message;

                    _state.Value = State.Failed;
                }
            });
        }
        public PlaybackShuffleActions(InterfaceActionService actionService, PlaybackActions playbackActions)
            : base(actionService, "PlaybackShuffle")
        {
            playback_actions = playbackActions;
            Actions.AddActionGroup(this);

            Add(new ActionEntry [] {
                new ActionEntry("ShuffleMenuAction", null,
                                Catalog.GetString("Shuffle"), null,
                                Catalog.GetString("Shuffle"), null)
            });

            Add(new RadioActionEntry [] {
                new RadioActionEntry("ShuffleOffAction", null,
                                     Catalog.GetString("Shuffle _Off"), null,
                                     Catalog.GetString("Do not shuffle playlist"),
                                     (int)PlaybackShuffleMode.Linear),

                new RadioActionEntry("ShuffleSongAction", null,
                                     Catalog.GetString("Shuffle by _Song"), null,
                                     Catalog.GetString("Play songs randomly from the playlist"),
                                     (int)PlaybackShuffleMode.Song),

                new RadioActionEntry("ShuffleArtistAction", null,
                                     Catalog.GetString("Shuffle by A_rtist"), null,
                                     Catalog.GetString("Play all songs by an artist, then randomly choose another artist"),
                                     (int)PlaybackShuffleMode.Artist),

                new RadioActionEntry("ShuffleAlbumAction", null,
                                     Catalog.GetString("Shuffle by A_lbum"), null,
                                     Catalog.GetString("Play all songs from an album, then randomly choose another album"),
                                     (int)PlaybackShuffleMode.Album),

                new RadioActionEntry("ShuffleRatingAction", null,
                                     Catalog.GetString("Shuffle by _Rating"), null,
                                     Catalog.GetString("Play songs randomly, prefer higher rated songs"),
                                     (int)PlaybackShuffleMode.Rating),

                new RadioActionEntry("ShuffleScoreAction", null,
                                     Catalog.GetString("Shuffle by S_core"), null,
                                     Catalog.GetString("Play songs randomly, prefer higher scored songs"),
                                     (int)PlaybackShuffleMode.Score)
            }, 0, OnActionChanged);

            this["ShuffleOffAction"].StockId     = Gtk.Stock.MediaNext;
            this["ShuffleSongAction"].IconName   = "media-playlist-shuffle";
            this["ShuffleArtistAction"].IconName = "media-playlist-shuffle";
            this["ShuffleAlbumAction"].IconName  = "media-playlist-shuffle";
            this["ShuffleRatingAction"].IconName = "media-playlist-shuffle";
            this["ShuffleScoreAction"].IconName  = "media-playlist-shuffle";

            ServiceManager.PlaybackController.ShuffleModeChanged += OnShuffleModeChanged;
            ServiceManager.PlaybackController.SourceChanged      += OnPlaybackSourceChanged;

            Gtk.Action action = this[ConfigIdToActionName(ShuffleMode.Get())];
            if (action is RadioAction)
            {
                active_action = (RadioAction)action;
            }
            else
            {
                Active = (RadioAction)this["ShuffleOffAction"];
            }

            Active.Activate();
        }