Пример #1
0
 public SearchTrack(Track track)
     : this(track.MediaId, track.ConvertedMediaTypeId, track.Title, track.Artist, track.Album, Convert.ToInt32(track.Duration.TotalSeconds))
 {
 }
Пример #2
0
        /// <summary>
        /// Gets an amount of tracks from the current track list. The result is received through an asynchronous callback.
        /// </summary>
        /// <param name="startIndex">The start index of the current track list.</param>
        /// <param name="count">The track count (0 for all tracks).</param>
        /// <param name="callback">The callback when the track data arrives.</param>
        /// <exception cref="System.ArgumentOutOfRangeException"/>
        /// <exception cref="System.ArgumentNullException"/>
        /// <exception cref="System.IndexOutOfRangeException"/>
        /// <seealso cref="TrackListChanged"/>
        /// <seealso cref="MAX_TRACKS"/>
        public void GetTracks(int startIndex, int count, TrackListCallback callback)
        {
            if (startIndex < 0)
                throw new ArgumentOutOfRangeException("startIndex", startIndex, "The start index must be >= 0!");
            if (count < 0)
                throw new ArgumentOutOfRangeException("count", count, "Count must be >= 0!");
            if (callback == null)
                throw new ArgumentNullException("callback");

            if (!IsReady || !TransportControls.Instance.HasPlaylist)
                return;

            Application.DeferredInvoke(new DeferredInvokeHandler(delegate(object sender)
            {
                // Make a local copy of the playlist to avoid race conditions
                ArrayListDataSet playlist = new ArrayListDataSet();
                playlist.CopyFrom(TransportControls.Instance.CurrentPlaylist);

                if (playlist == null)
                    return;

                if (count == 0)
                    count = playlist.Count - startIndex;

                if (count > ZuneApi.MAX_TRACKS)
                    count = ZuneApi.MAX_TRACKS;

                if (startIndex + count > playlist.Count)
                    throw new IndexOutOfRangeException("Start index (" + startIndex + ") + count ("
                        + count + ") must be <= TrackCount (" + playlist.Count + ")!");

                Track[] tracks = new Track[count];
                for (int i = 0; i < count; i++)
                {
                    int playlistIndex = i + startIndex;
                    object playlistItem = playlist[playlistIndex];
                    if (playlistItem is PlaybackTrack)
                        tracks[i] = new Track((PlaybackTrack)playlistItem, playlistIndex);
                    else
                        tracks[i] = new Track();
                }

                callback(tracks);
            }), DeferredInvokePriority.Low); // low priority to save performance
        }
Пример #3
0
        /// <summary>
        /// Initializes a new instance of the <see cref="ZuneApi"/> class.
        /// <para>
        /// <remarks>Note that you have to call the <see cref="Launch(string)"/>-method to start the Zune software.</remarks>
        /// </para>
        /// </summary>
        public ZuneApi()
        {
            IsRunning = IsReady = IsClosed = false;
            PlayerState = PlayerState.Uninitialized;
            TrackState = TrackState.Invalid;
            CurrentTrack = new Track();
            TrackType = TrackType.None;

            LUCENE_INDEX_DIRECTORY = Environment.GetEnvironmentVariable("localappdata") + "\\VosSoft\\ZuneApi";

            ZuneApi.Instance = this;
        }
Пример #4
0
        /// <summary>
        /// Handles the PropertyChanged event of the TransportControls of the Zune player.
        /// This is used for low level access on the TransportControls.
        /// </summary>
        /// <param name="sender">The source of the event.</param>
        /// <param name="e">The <see cref="System.ComponentModel.PropertyChangedEventArgs"/> instance containing the event data.</param>
        private void TransportControls_PropertyChanged(object sender, PropertyChangedEventArgs e)
        {
            if (e.PropertyName.Equals(ZuneApi.TC_CurrentTrack)) // the current track has changed
            {
                TrackType oldTrackType = TrackType;

                // remove old track rating event handler
                if (CurrentTrack != null)
                    CurrentTrack.RatingChanged -= CurrentTrack_RatingChanged;

                if (TransportControls.Instance.CurrentTrack == null) // playlist removed
                {
                    CurrentTrack = new Track(); // the track is always valid for compatibility
                    TrackType = TrackType.None;
                }
                else
                {
                    PlaybackTrack playbackTrack = TransportControls.Instance.CurrentTrack;
                    CurrentTrack = new Track(playbackTrack, TransportControls.Instance.CurrentTrackIndex);

                    switch (playbackTrack.MediaType)
                    {
                        case MediaType.Track:
                        case MediaType.AudioMP4:
                        case MediaType.AudioMP3:
                        case MediaType.AudioWMA:
                        case MediaType.AudioWAV:
                        case MediaType.AudioQT:
                            TrackType = TrackType.Music;
                            break;
                        case MediaType.Video:
                        case MediaType.VideoMP4:
                        case MediaType.VideoMPG:
                        case MediaType.VideoWMV:
                        case MediaType.VideoQT:
                        case MediaType.VideoDVRMS:
                        case MediaType.VideoMBR:
                        case MediaType.VideoAVI:
                            TrackType = TrackType.Video;
                            break;
                        case MediaType.PodcastEpisode:
                        case MediaType.Podcast:
                            TrackType = TrackType.Podcast;
                            break;
                        default:
                            TrackType = TrackType.Undefined;
                            break;
                    }
                }

                if (TrackChanged != null)
                    TrackChanged(this, EventArgs.Empty);

                if (TrackTypeChanged != null && TrackType != oldTrackType)
                    TrackTypeChanged(this, EventArgs.Empty);

                // user rating, fire change event immediately and hook up event handler
                CurrentTrack_RatingChanged(this, EventArgs.Empty);
                CurrentTrack.RatingChanged += CurrentTrack_RatingChanged;
            }
            else if (e.PropertyName.Equals(ZuneApi.TC_CurrentPlaylist)) // the current playlist has changed
            {
                if (TransportControls.Instance.CurrentPlaylist == null) // playlist removed
                {
                    TrackCount = 0;

                    if (TrackListChanged != null)
                        TrackListChanged(this, EventArgs.Empty);

                    return;
                }

                TransportControls.Instance.CurrentPlaylist.ContentsChanged += CurrentPlaylist_ContentsChanged;

                GetTrackCount();

                // TODO: the current track index might have changed!
            }
        }