Example #1
0
        public object Execute(object sender, object parameter)
        {
            if (Track == null && parameter == null)
            {
                return(null);
            }

            IAudioTrack track = null;

            if (Track == null)
            {
                if (InputConverter != null)
                {
                    track = (IAudioTrack)InputConverter.Convert(parameter, null, null, null);
                }
                else
                {
                    track = (IAudioTrack)parameter;
                }
            }
            else
            {
                track = Track;
            }

            Messenger.Default.Send(new PlayTrackMessage {
                Tracks = (IEnumerable <IAudioTrack>)TracksList, TrackToPlay = track
            });
            NavigationHelper.Navigate(AppViews.PlayerView);

            return(null);
        }
 private IAudioTrack CreateAudioTrack()
 {
     _audioSource               = _factory.AudioSourceWithConstraints(_audioConstraints);
     _localAudioTrack           = _factory.AudioTrackWithSource(_audioSource, AudioTrackId);
     _localAudioTrack.IsEnabled = _enableAudio;
     return(_localAudioTrack);
 }
Example #3
0
        public void Play()
        {
            try
            {
                lock (_updateLock)
                {
                    Stop();
                    _isPlaying = true;

                    if (_musicEntry.Value != null)
                    {
                        _audioTrack = _engine.CreateTrack(
                            ResourceManager.GetResourcePath(_musicEntry.Value.FileName));

                        GameLog.Client.Audio.DebugFormat("called! _musicEntry.Value.FileName: {0}", _musicEntry.Value.FileName);

                        if (_audioTrack != null)
                        {
                            _audioTrack.Group = _channelGroup;
                            _audioTrack.Play(OnTrackEnd);

                            if (_updateTimerSubscription == null)
                            {
                                _updateTimerSubscription = _updateTimer.Subscribe();
                            }
                        }
                    }
                }
            }
            catch (Exception e)
            {
                GameLog.Client.Audio.Error(e);
            }
        }
Example #4
0
 private IAudioTrack CreateAudioTrack()
 {
     _audioSource               = _factory.CreateAudioSource(_audioConstraints);
     _localAudioTrack           = _factory.CreateAudioTrack(AudioTrackId, _audioSource);
     _localAudioTrack.IsEnabled = _enableAudio;
     return(_localAudioTrack);
 }
Example #5
0
        public RawAudioTrackInfo(IAudioTrack audio)
            : this()
        {
            this.Hints = audio.ParentStream.Hints;
            if ((this.ChannelCount != (short)audio.ChannelCount) ||
                (this.SampleSize != (short)audio.SampleSize) ||
                (this.SampleRate != audio.SampleRate))
            {
                // overwrite what was derived from PrivateCodecData
                this.ChannelCount = (short)audio.ChannelCount;
                this.SampleSize   = (short)audio.SampleSize;
                this.SampleRate   = audio.SampleRate;
            }
            this.PayloadType   = audio.PayloadType;
            this.TrackID       = 0; // set destination track ID for audio to zero
            this.SourceTrackID = audio.TrackID;
            if (audio.TrackFormat != null)
            {
                this.DurationIn100NanoSecs = audio.TrackFormat.DurationIn100NanoSecs; // track specific duration, in 100 nanosec units
                this.TimeScale             = audio.TrackFormat.TimeScale;             // track specific time scale
            }
            else
            {
                this.DurationIn100NanoSecs = audio.TrackDurationIn100NanoSecs; // track specific duration, in 100 nanosec units
                this.TimeScale             = (uint)audio.SampleRate;           // track specific time scale
            }

            this.CodecPrivateData = audio.Codec.PrivateCodecData;
        }
Example #6
0
 private void TrackChanged(object sender, IAudioTrack e)
 {
     if (TracksList == null)
     {
         return;
     }
     TracksList.ScrollIntoView(vm.CurrentTrack);
 }
Example #7
0
        /// <summary>
        /// Перемешать треки или вернуть обратно.
        /// </summary>
        /// <param name="isOn"></param>
        private async Task ShuffleTracks(bool isOn, IAudioTrack currentTrack)
        {
            if (!isOn)
            {
                if (_normalTrackList == null)
                {
                    return;
                }
                Tracks           = new ObservableCollection <IAudioTrack>(_normalTrackList);
                _normalTrackList = null;
                _currentTrackID  = Tracks.IndexOf(_currentTrack);
                ServiceHelper.PlayerService.UpdateShuffleMode();
                return;
            }
            else if (Tracks == null)
            {
                return;
            }

            CanShuffle = false;
            await CoreHelper.Dispatcher.RunAsync(CoreDispatcherPriority.Normal, () =>
            {
                _normalTrackList = new List <IAudioTrack>(Tracks);
                var newTracks    = new List <IAudioTrack>(Tracks);

                for (int i = 0; i < newTracks.Count; i++)
                {
                    int id = _random.Next(0, _normalTrackList.Count);
                    if (id == i)
                    {
                        continue;
                    }

                    var track     = newTracks[i];
                    newTracks[i]  = newTracks[id];
                    newTracks[id] = track;
                }

                Tracks    = new ObservableCollection <IAudioTrack>(newTracks);
                newTracks = null;

                int currentID = Tracks.IndexOf(currentTrack);
                if (currentID > 0)
                {
                    var track         = Tracks[0];
                    Tracks[0]         = Tracks[currentID];
                    Tracks[currentID] = track;
                }
                _currentTrackID = 0;
            });

            await ServiceHelper.PlayerService.SetNewShuffledPlaylist(Tracks);

            ServiceHelper.PlayerService.UpdateShuffleMode();
            CanShuffle = true;
        }
        public bool PlaySound(AudioClip clip, SoundType type, uint id)
        {
            IAudioTrack audio = GetAudioTrack(type);

            if (audio != null)
            {
                audio.PlaySound(id, clip);
                return(true);
            }
            return(false);
        }
Example #9
0
        /// <summary>
        /// Сравнивает два трека на равенство.
        /// </summary>
        /// <param name="other">Другой трек.</param>
        public bool Equals(IAudioTrack other)
        {
            if (ReferenceEquals(this, other))
            {
                return(true);
            }

            return(this.Title == other.Title &&
                   this.Artist == other.Artist &&
                   this.Source == other.Source);
        }
        private IAudioTrack[] GetAudioTracks()
        {
            var items = _mediaStream.AudioTracks;
            var arr   = new IAudioTrack[items.Count];

            for (int i = 0; i < items.Count; i++)
            {
                arr[i] = new AudioTrackNative((AudioTrack)items[i]);
            }

            return(arr);
        }
Example #11
0
        public void Dispose()
        {
            if (_isDisposed)
            {
                return;
            }

            _isDisposed = true;

            lock (_updateLock)
            {
                if (_updateTimerSubscription != null)
                {
                    _updateTimerSubscription.Dispose();
                    _updateTimerSubscription = null;
                }

                if (_audioTrack != null)
                {
                    try
                    {
                        _audioTrack.Stop();
                        _audioTrack.Dispose();
                        _audioTrack = null;
                    }
                    catch (Exception e)
                    {
                        GameLog.Client.Audio.Error(e);
                    }
                }

                foreach (var track in _endingTracks)
                {
                    try
                    {
                        track.Stop();
                        track.Dispose();
                    }
                    catch (Exception e)
                    {
                        GameLog.Client.Audio.Error(e);
                    }
                }
                _endingTracks.Clear();

                if (_channelGroup != null)
                {
                    _channelGroup.Dispose();
                    _channelGroup = null;
                }
                _engine = null;
            }
        }
Example #12
0
 private void OnTrackEnd(IAudioTrack track)
 {
     lock (_updateLock)
     {
         try
         {
             track.Dispose();
             _audioTracks.Remove(track);
         }
         catch (Exception e)
         {
             GameLog.Client.Audio.Error(e);
         }
     }
 }
Example #13
0
        public async Task Info_AudioProperties_True()
        {
            IMediaInfo info = await MediaInfo.Get(Resources.MKV_Raw_MultipleTracks);

            IAudioTrack audioTrack = info.AudioTracks.FirstOrDefault();

            Assert.NotNull(audioTrack);
            Assert.Equal(3141027, audioTrack.Bitrate);
            Assert.Equal(20, audioTrack.Duration);
            Assert.Equal("lossless", audioTrack.CompressionMode.ToLower());
            Assert.Equal("mlp fba", audioTrack.Format.ToLower());
            Assert.Equal(960000, audioTrack.SamplingCount);
            Assert.Equal(48000, audioTrack.SamplingRate);
            Assert.Equal(1, audioTrack.StreamOrder);
            Assert.Equal("en", audioTrack.Language.ToLower());
        }
Example #14
0
        /// <summary>
        /// Загрузит обложку альбома.
        /// </summary>
        /// <param name="track">Трек.</param>
        /// <param name="mbid">Идентификатор трека (если имеется).</param>
        private async void LoadAlbumImage(IAudioTrack track, string mbid = null)
        {
            TrackImage = new BitmapImage(new Uri("ms-appx:///Assets/Logo.scale-240.png"));

            TrackGetInfoRequest request = String.IsNullOrWhiteSpace(mbid) ?
                                          new TrackGetInfoRequest(track.Title, track.Artist) :
                                          new TrackGetInfoRequest(mbid);

            var response = await request.ExecuteAsync();

            if (response.IsValid() && response.ErrorType == LFErrors.None &&
                response.Track.Album != null && track == CurrentTrack)
            {
                if (!String.IsNullOrEmpty(response.Track.Album.MaxImage.URL))
                {
                    TrackImage = new BitmapImage(new Uri(response.Track.Album.MaxImage.URL));
                }
            }
        }
Example #15
0
        private void OnTrackEnd(IAudioTrack track)
        {
            try
            {
                lock (_updateLock)
                {
                    try
                    {
                        track.Dispose();
                    }
                    catch (Exception e)
                    {
                        GameLog.Client.Audio.Error(e);
                    }

                    if (track == _audioTrack)
                    {
                        _audioTrack = null;
                        Next();
                    }
                    else
                    {
                        _endingTracks.Remove(track);
                    }

                    if (_audioTrack == null && _endingTracks.Count == 0)
                    {
                        if (_updateTimerSubscription != null)
                        {
                            _updateTimerSubscription.Dispose();
                            _updateTimerSubscription = null;
                        }
                    }
                }
            }
            catch (Exception e)
            {
                GameLog.Client.Audio.Error(e);
            }
        }
Example #16
0
        public void Stop()
        {
            try
            {
                lock (_updateLock)
                {
                    _isPlaying = false;

                    if (_audioTrack == null)
                    {
                        return;
                    }

                    if (!_audioTrack.IsPlaying)
                    {
                        try
                        {
                            _audioTrack.Stop();
                            GameLog.Client.Audio.DebugFormat("Stop - Group={0}, Track={1}", _audioTrack.Group.ToString(), _audioTrack);
                            _audioTrack.Dispose();
                            _audioTrack = null;
                        }
                        catch (Exception e)
                        {
                            GameLog.Client.Audio.Error(e);
                        }
                    }
                    else
                    {
                        _endingTracks.Add(_audioTrack);
                        _audioTrack = null;
                    }
                }
            }
            catch (Exception e)
            {
                GameLog.Client.Audio.Error(e);
            }
        }
 public void AddTrack(IAudioTrack audioTrack)
 {
     _mediaStream.AddTrack(audioTrack.ToNative <AudioTrack>());
 }
Example #18
0
        public RawAudioTrackInfo(IAudioTrack audio)
            : this()
        {
            this.Hints = audio.ParentStream.Hints;
              if ((this.ChannelCount != (short)audio.ChannelCount) ||
              (this.SampleSize != (short)audio.SampleSize) ||
              (this.SampleRate != audio.SampleRate))
              {
            // overwrite what was derived from PrivateCodecData
            this.ChannelCount = (short)audio.ChannelCount;
            this.SampleSize = (short)audio.SampleSize;
            this.SampleRate = audio.SampleRate;
              }
              this.PayloadType = audio.PayloadType;
              this.TrackID = 0; // set destination track ID for audio to zero
              this.SourceTrackID = audio.TrackID;
              if (audio.TrackFormat != null)
              {
            this.DurationIn100NanoSecs = audio.TrackFormat.DurationIn100NanoSecs; // track specific duration, in 100 nanosec units
            this.TimeScale = audio.TrackFormat.TimeScale; // track specific time scale
              }
              else
              {
            this.DurationIn100NanoSecs = audio.TrackDurationIn100NanoSecs; // track specific duration, in 100 nanosec units
            this.TimeScale = (uint)audio.SampleRate; // track specific time scale
              }

              this.CodecPrivateData = audio.Codec.PrivateCodecData;
        }
Example #19
0
 public void OnAudioTrackRemoved(IConversation conversation, IParticipant participant, IAudioTrack audioTrack)
 {
     AudioTrackRemovedHandler?.Invoke(conversation, participant, audioTrack);
 }
        private void SwitchMediaPlayerSource(IAudioTrack audioTrack, IVideoTrack videoTrack)
        {
            //lock (_mediaPlaybackLock)
            //{
            //    if (videoTrack != _playbackVideoTrack)
            //    {
            //        // Notify media player that source changed
            //        if (_isVideoPlaying)
            //        {
            //            _videoStreamSource.NotifyError(MediaStreamSourceErrorStatus.ConnectionToServerLost);
            //            _videoPlayer.Pause();
            //            _isVideoPlaying = false;
            //        }

            //        // Detach old source
            //        if (_playbackVideoTrack != null)
            //        {
            //            _playbackVideoTrack.I420AVideoFrameReady -= VideoTrack_I420AFrameReady;
            //            _videoWidth = 0;
            //            _videoHeight = 0;
            //            ClearVideoStats();
            //        }

            //        _playbackVideoTrack = videoTrack;

            //        // Attach new source
            //        if (_playbackVideoTrack != null)
            //        {
            //            _playbackVideoTrack.I420AVideoFrameReady += VideoTrack_I420AFrameReady;
            //        }

            //        LogMessage($"Changed video playback track.");
            //    }

            //    if (audioTrack != _playbackAudioTrack)
            //    {
            //        // Detach old source
            //        if (_playbackAudioTrack != null)
            //        {
            //            _playbackAudioTrack.AudioFrameReady -= AudioTrack_FrameReady;
            //            _audioSampleRate = 0;
            //            _audioChannelCount = 0;
            //            ClearRemoteAudioStats();
            //        }

            //        _playbackAudioTrack = audioTrack;

            //        // Attach new source
            //        if (_playbackAudioTrack != null)
            //        {
            //            _playbackAudioTrack.AudioFrameReady += AudioTrack_FrameReady;
            //        }

            //        LogMessage($"Changed video playback track.");
            //    }
            //}

            //// Update local media overlay panel
            //bool hasLocalMedia = ((_playbackVideoTrack != null) || (_playbackAudioTrack != null));
            //localMediaPanel.Visibility = (hasLocalMedia ? Visibility.Visible : Visibility.Collapsed);
            //muteLocalAudio.IsEnabled = (_playbackAudioTrack != null);
            //muteLocalVideo.IsEnabled = (_playbackVideoTrack != null);
        }
Example #21
0
        public void RemoveAudioTrack(IAudioTrack audioTrack)
        {
            _tracks.Remove(audioTrack);

            audioTrack.Dispose();
        }
Example #22
0
 /// <summary>
 /// Вовзвращает значение, равнли объекты.
 /// </summary>
 /// <param name="other">Объект для сравнения.</param>
 public bool Equals(IAudioTrack other)
 {
     return(this.Title == other.Title &&
            this.Artist == other.Artist &&
            this.Source == other.Source);
 }
Example #23
0
 /// <summary>
 /// Установить новый трек.
 /// </summary>
 /// <param name="track">Трек.</param>
 private void SetNewTrack(IAudioTrack track)
 {
     _isPopSended    = false;
     _currentTrackID = Tracks.IndexOf(track);
     PlayTrackFromID(_currentTrackID);
 }
Example #24
0
 /// <summary>
 /// Загружает информацию о треке.
 /// </summary>
 /// <param name="title">Заголовок трека.</param>
 /// <param name="artist">Исполнитель трека.</param>
 /// <param name="mbid">Идентификатор трека (если имеется).</param>
 private void LoadTrackInfo(IAudioTrack track, string mbid = null)
 {
     RaisePropertyChanged(() => IsPlayerWork);
     LoadAlbumImage(track, mbid);
     LoadArtistsImage(track);
 }
 public void RemoveTrack(IAudioTrack audioTrack)
 {
     _mediaStream.RemoveTrack(audioTrack.ToNative <AudioTrack>());
 }
 public void AddTrack(IAudioTrack audio)
 {
     Tracks.Add(audio);
 }
Example #27
0
        /// <summary>
        /// Загрузить картинку исполнителя трека.
        /// </summary>
        /// <param name="track">Трек.</param>
        private async void LoadArtistsImage(IAudioTrack track)
        {
            var pop = new PopupMessage()
            {
                Title     = CurrentTrack.Artist,
                Content   = CurrentTrack.Title,
                Type      = PopupMessageType.Info,
                Parameter = new NavigateToPageMessage()
                {
                    Page = AppViews.PlayerView
                }
            };

            Uri artistImageUri = await ImagesHelper.GetCachedArtistImage(track.Artist);

            if (track == CurrentTrack)
            {
                if (artistImageUri != null)
                {
                    ArtistImage  = new BitmapImage(artistImageUri);
                    pop.ImageUrl = artistImageUri.ToString();
                    if (!_isPopSended && !_isOnView)
                    {
                        Messenger.Default.Send(pop);
                    }
                    _isPopSended = true;
                    return;
                }

                ArtistImage = new BitmapImage();
            }
            else
            {
                return;
            }

            if (!_isPopSended && !_isOnView)
            {
                Messenger.Default.Send(pop);
            }
            _isPopSended = true;
            string artistUrl = null;

            artistUrl = await ServiceHelper.XboxMusicService.GetArtistImageURL(track.Artist, 480, 800);

            if (String.IsNullOrEmpty(artistUrl))
            {
                var response = await(new ArtistGetInfoRequest(track.Artist, false)).ExecuteAsync();
                if (response.ErrorType == LFErrors.None && response.IsValid())
                {
                    artistUrl = response.Artist.MegaImage.URL;
                    if (String.IsNullOrEmpty(artistUrl))
                    {
                        return;
                    }
                }
                else
                {
                    return;
                }
            }

            artistImageUri = await ImagesHelper.CacheAndGetArtistsImage(track.Artist, artistUrl);

            if (artistImageUri != null && track == CurrentTrack)
            {
                ArtistImage = new BitmapImage(artistImageUri);
                return;
            }
        }