Example #1
0
            public static StreamPlayer Create(MusicStream Wave)
            {
                var Return = new StreamPlayer();

                Return.Init(Wave);
                return(Return);
            }
Example #2
0
            /*
             * public static StreamPlayer Create(int Frequency, TimeSpan Duration, bool Loop = false, float Volume = 1) =>
             *  Create(new ToneStream(Frequency, Duration, Loop, Volume));
             * public static StreamPlayer Play(int Frequency, TimeSpan Duration, bool Loop = false, float Volume = 1) =>
             *  Play(new ToneStream(Frequency, Duration, Loop, Volume));
             * public static StreamPlayer Create(int Frequency, int Seconds = 1, bool Loop = false, float Volume = 1) =>
             *  Create(new ToneStream(Frequency, Seconds, Loop, Volume));
             * public static StreamPlayer Play(int Frequency, int Seconds = 1, bool Loop = false, float Volume = 1) =>
             *  Play(new ToneStream(Frequency, Seconds, Loop, Volume));
             */
            public static StreamPlayer Play(MusicStream Stream)
            {
                var Return = Create(Stream);

                Return.Play();
                return(Return);
            }
Example #3
0
        public MainPageViewModel()
        {
            _musicStream = new MusicStream();
            log          = new ObservableCollection <string>();
            playing      = false;

            Initialize();
        }
Example #4
0
 protected void Init(MusicStream Wave)
 {
     _mode = (AudioTrackMode)Wave.Mode;
     if (_mode == AudioTrackMode.Static)
     {
         _player = new AudioTrack(
             // Stream type
             (Android.Media.Stream)Wave.Type,
             // Frequency
             Wave.SampleRate,
             // Mono or stereo
             (ChannelOut)Wave.Config,
             // Audio encoding
             (Encoding)Wave.Format,
             // Length of the audio clip.
             (int)Wave.SizeInBytes,
             // Mode. Stream or static.
             AudioTrackMode.Static);
     }
     else
     {
         _player = new AudioTrack(
             // Stream type
             (Android.Media.Stream)Wave.Type,
             // Frequency
             Wave.SampleRate,
             // Mono or stereo
             (ChannelOut)Wave.Config,
             // Audio encoding
             (Encoding)Wave.Format,
             // Length of the audio clip.
             _buffersize = AudioTrack.GetMinBufferSize(Wave.SampleRate,
                                                       (ChannelOut)Wave.Config, (Encoding)Wave.Format),
             // Mode. Stream or static.
             AudioTrackMode.Stream);
     }
     _duration = Wave.Duration;
     _loop     = Wave.Loop;
     _frames   = Wave.Samples;
     _player.SetVolume(_volume = Wave.Volume);
     _player.SetNotificationMarkerPosition(_frames * 31 / 32);
     if (_mode == AudioTrackMode.Static)
     {
         _player.Write(Wave.Content.ReadFully(true), 0, (int)Wave.Content.Length);
     }
     else
     {
         Set((sender, e) => { if (_loop)
                              {
                                  _player.Release(); Init(_Wave); Write();
                              }
                              ; });
         _content = Wave.Content.ReadFully(true);
     }
     _prepared = true;
 }
Example #5
0
        public MusicStream GetMusicStream(Track track, File file, TimeSpan timeout)
        {
            ISpotify connection = GetConnection();

            MusicStream result = connection.GetMusicStream(track, file, timeout);

            ReleaseConnection(connection);

            return(result);
        }
Example #6
0
 protected void Init(MusicStream Wave)
 {
     _player = new MediaElement
     {
         IsMuted   = false,
         Position  = new TimeSpan(0, 0, 0),
         Volume    = Wave.Volume,
         IsLooping = Wave.Loop,
     };
     _player.SetSource(Wave.Content.AsRandomAccessStream(), Wave.MimeType);
 }/*
Example #7
0
            protected void Init(MusicStream Wave)
            {// To get preferred buffer size and sampling rate.
                AudioManager audioManager = (AudioManager)
                                            Forms.Context.GetSystemService(Android.Content.Context.AudioService);

                Rate = int.Parse(audioManager.GetProperty(AudioManager.PropertyOutputSampleRate));
                //string Size = audioManager.GetProperty(AudioManager.PropertyOutputFramesPerBuffer);
                SampleRate = Wave.SampleRate;

                _content = Wave.Content;
                int SizeInBytes = Wave.SizeInBytes - 44;

                _player = new AudioTrack(
                    // Stream type
                    (Android.Media.Stream)Wave.Type,
                    // Frequency
                    Rate,
                    // Mono or stereo
                    (ChannelOut)Wave.Config,
                    // Audio encoding
                    (Encoding)Wave.Format,
                    // Length of the audio clip.
                    SizeInBytes,
                    // Mode. Stream or static.
                    (AudioTrackMode)Wave.Mode);
                _loop   = Wave.Loop;
                _volume = Wave.Volume;
                _player.SetVolume(_volume = Wave.Volume);
#if true
                //int ch = Wave.Channels;
                //_start = 0;// (int)Wave.Content.Length / ch;
                //_stop = (int)Wave.Content.Length;// / ch / 2 / 2 + 16000
#elif false
                _player.SetNotificationMarkerPosition(SizeInBytes / 2);
                _player.MarkerReached += (object sender, AudioTrack.MarkerReachedEventArgs e) =>
                { if (_loop)
                  {
                      e.Track.SetPlaybackHeadPosition(0);
                  }
                };
#elif false
                Device.StartTimer(Wave.Duration, () => { if (_loop)
                                                         {
                                                             _player.SetPlaybackHeadPosition(0);
                                                         }
                                                         return(_loop); });
#endif
                _prepared = true;
            }
Example #8
0
        public async Task <IActionResult> Edit([FromForm] MusicStream request)
        {
            try
            {
                var validation = _editMusicInfoValidator.Validate(request);

                if (!validation.IsValid)
                {
                    return(this.ErrorResult(HttpStatusCode.BadRequest, validation.Errors));
                }

                await _cloudStorage.EditMusicInfo(request);

                return(Ok("Data updated successfully"));
            }
            catch (Exception e)
            {
                _logger.LogError(e, "Failed to update the data");
                return(this.ErrorResult(HttpStatusCode.InternalServerError, "InternalServerError", "An error occured while processing this request."));
            }
        }
Example #9
0
        public ChannelStreamer(Protocol protocol, Media.File file, byte[] key, MusicStream output)
        {
            if (key.Length != (128 / 8))
            {
                output.AllAvailable = true;
                throw new InvalidDataException("Encryption key for channel must be 128-bit.");
            }

            _cipher.BlockSize = 128;
            _cipher.KeySize   = 128;
            _key            = key;
            _cipher.Mode    = CipherMode.ECB; //CTR not available
            _cipher.Padding = PaddingMode.None;

            _output = output;

            _file     = file;
            _protocol = protocol;

            _channelLength = 160 * 1024 * 5 / 8; /* 160 kbit * 5 seconds. */

            /* Send first substream request. */
            string hash = this._cache.Hash(this._file, this._channelOffset, this._channelLength);

            if (this._cache != null && this._cache.Contains("substream", hash))
            {
                this._cache.Load("substream", hash, this);
            }
            else
            {
                try
                {
                    this._protocol.SendSubstreamRequest(this, this._file, this._channelOffset, this._channelLength);
                }
                catch (ProtocolException)
                {
                    return;
                }
            }
        }
Example #10
0
        public async Task EditMusicInfo(MusicStream musicStream)
        {
            var blobContainer = await _storageConnectionFactory.GetContainer();

            string filename = Path.GetFileName(musicStream.uri.LocalPath);

            var blob = blobContainer.GetBlockBlobReference(filename);
            //
            var metadataKeys = new string[] { "title", "artist" };

            foreach (string key in metadataKeys)
            {
                if (blob.Metadata.ContainsKey(key))
                {
                    blob.Metadata[key] = key == "title" ? musicStream.title : musicStream.artist;
                }
                else
                {
                    blob.Metadata.Add(key, key == "title" ? musicStream.title : musicStream.artist);
                }
            }
            //
            blob.SetMetadata();
        }
Example #11
0
 public static StreamPlayer Create(MusicStream Wave)
 {
     return(new StreamPlayer {
         _Wave = Wave
     });
 }
Example #12
0
 protected void Init(MusicStream Wave)
 {
     _player = AVAudioPlayer.FromData(NSData.FromStream(Wave.Content));
     _player.NumberOfLoops = Wave.Loop ? 0 : -1;
     _player.Volume        = Wave.Volume;
 }
Example #13
0
        public override int RenderVisualization()
        {
            try
            {
                if (VisualizationWindow == null || !VisualizationWindow.Visible || _visParam.VisHandle == 0)
                {
                    return(0);
                }

                // Any is wrong with PlaybackStateChanged, if the songfile automatically changed
                // so i have create a new variable which fix this problem
                if (Bass != null)
                {
                    if (Bass.CurrentFile != _OldCurrentFile && !Bass.IsRadio)
                    {
                        trackTag = TagReader.TagReader.ReadTag(Bass.CurrentFile);
                        if (trackTag != null)
                        {
                            _songTitle      = String.Format("{0} - {1}", trackTag.Artist, trackTag.Title);
                            _OldCurrentFile = Bass.CurrentFile;
                        }
                        else
                        {
                            _songTitle = "   ";
                        }
                    }

                    // Set Song information, so that the plugin can display it
                    if (trackTag != null && !Bass.IsRadio)
                    {
                        _playlistPlayer = PlayListPlayer.SingletonPlayer;
                        PlayListItem curPlaylistItem = _playlistPlayer.GetCurrentItem();

                        MusicStream streams = Bass.GetCurrentStream();
                        // Do not change this line many Plugins search for Songtitle with a number before.
                        _mediaInfo.SongFile    = Bass.CurrentFile;
                        _mediaInfo.SongTitle   = (_playlistPlayer.CurrentPlaylistPos + 1) + ". " + _songTitle;
                        _mediaInfo.Position    = (int)(1000 * Bass.CurrentPosition);
                        _mediaInfo.Duration    = (int)Bass.Duration;
                        _mediaInfo.PlaylistLen = 1;
                        _mediaInfo.PlaylistPos = _playlistPlayer.CurrentPlaylistPos;
                    }
                    else
                    {
                        if (Bass.IsRadio)
                        {
                            // Change TrackTag to StreamTag for Radio
                            trackTag = Bass.GetStreamTags();
                            if (trackTag != null)
                            {
                                // Artist and Title show better i think
                                _songTitle           = trackTag.Artist + ": " + trackTag.Title;
                                _mediaInfo.SongTitle = _songTitle;
                            }
                            else
                            {
                                _songTitle = "   ";
                            }
                            _mediaInfo.Position = (int)(1000 * Bass.CurrentPosition);
                        }
                        else
                        {
                            _mediaInfo.Position    = 0;
                            _mediaInfo.Duration    = 0;
                            _mediaInfo.PlaylistLen = 0;
                            _mediaInfo.PlaylistPos = 0;
                        }
                    }
                }

                if (IsPreviewVisualization)
                {
                    _mediaInfo.SongTitle = "Mediaportal Preview";
                }
                BassVis.BASSVIS_SetInfo(_visParam, _mediaInfo);

                if (RenderStarted)
                {
                    return(1);
                }

                int stream = 0;

                if (Bass != null)
                {
                    stream = (int)Bass.GetCurrentVizStream();
                }

                // ckeck is playing
                int nReturn = BassVis.BASSVIS_SetPlayState(_visParam, BASSVIS_PLAYSTATE.IsPlaying);
                if (nReturn == Convert.ToInt32(BASSVIS_PLAYSTATE.Play) && (_visParam.VisHandle != 0))
                {
                    // Do not Render without playing
                    if (MusicPlayer.BASS.Config.MusicPlayer == AudioPlayer.WasApi)
                    {
                        RenderStarted = BassVis.BASSVIS_RenderChannel(_visParam, stream, true);
                    }
                    else
                    {
                        RenderStarted = BassVis.BASSVIS_RenderChannel(_visParam, stream, false);
                    }
                }
            }

            catch (Exception) {}

            return(1);
        }
Example #14
0
        /// <summary>
        /// Handles the incoming connections.
        /// </summary>
        /// <param name="client">The socket that the connection uses.</param>
        /// <param name="cancellationToken">The <see cref="CancellationToken"/> for closing the connection.</param>
        private void server_Connection(TcpClient client, CancellationToken cancellationToken)
        {
            var reader = new StreamReader(client.GetStream());

            string request = "";
            Dictionary<string, string> headers = new Dictionary<string, string>();

            byte[] buffer = new byte[1];

            try
            {
                string received = null;

                while (received != "")
                {
                    received = reader.ReadLine();

                    if (received != null && received.Length > 2)
                    {
                        string[] splitReceived = received.Split(':');

                        if (splitReceived.Length < 2)
                        {
                            request = splitReceived[0];
                        }
                        else
                        {
                            if (!headers.ContainsKey(splitReceived[0]))
                                headers.Add(splitReceived[0], string.Join(":", splitReceived.Skip(1)).Trim());
                        }
                    }
                }
            }
            catch (Exception ex)
            {
                Console.WriteLine(ex.Message);
            }

            Console.WriteLine("Request: " + request);
            Console.WriteLine("Headers:");
            foreach (var header in headers)
            {
                Console.WriteLine(header.Key + ": " + header.Value);
            }
            Console.WriteLine("End of Headers");
            Console.WriteLine();

            var sendIcyMeta = headers.ContainsKey("Icy-MetaData") && headers["Icy-MetaData"] == "1";

            string[] requestSplit = request.Split(' ');

            if (streams.ContainsKey(requestSplit[1]))
            {
                streams[requestSplit[1]].AddClient(client, sendIcyMeta);

                if (!streams[requestSplit[1]].Running)
                    Task.Run(() => (Action)streams[requestSplit[1]].Run, cancellationToken);
            }
            else
            {
                string path = Path.Combine(rootDirectory.FullName, "Streams", requestSplit[1].TrimStart('/').Replace('/', Path.DirectorySeparatorChar) + ".json");

                if (File.Exists(path))
                {
                    MusicStream musicStream = new MusicStream(path);

                    musicStream.AddClient(client, sendIcyMeta);

                    Task.Run((Action)musicStream.Run, cancellationToken);

                    streams.Add(requestSplit[1], musicStream);
                }
                else
                {
                    client.Close();
                }
            }
        }