Esempio n. 1
0
        async Task <bool> Play(Windows.Media.Playback.IMediaPlaybackSource source)
        {
            Player.Source = source;
            Player.Play();

            return(await Ended.Task);
        }
Esempio n. 2
0
        public MainPage()
        {
            this.InitializeComponent();

            _mediaPlayer        = new Windows.Media.Playback.MediaPlayer();
            _mediaPlayer.Source = Windows.Media.Core.MediaSource.CreateFromUri(new Uri("ms-appx:///Assets/Kevin_MacLeod_-_Nu_Flute.mp3"));
            // TODO: need to reduce volume on startup
            _mediaPlayer.Play();
        }
Esempio n. 3
0
 //<SnippetRenderSoundLevelChanged>
 private void RenderAudioStateMonitor_SoundLevelChanged(AudioStateMonitor sender, object args)
 {
     if ((sender.SoundLevel == SoundLevel.Full) ||
         (sender.SoundLevel == SoundLevel.Low && !isPodcast))
     {
         mediaPlayer.Play();
     }
     else if ((sender.SoundLevel == SoundLevel.Muted) ||
              (sender.SoundLevel == SoundLevel.Low && isPodcast))
     {
         // Pause playback if we’re muted or if we’re playing a podcast and are ducked
         mediaPlayer.Pause();
     }
 }
Esempio n. 4
0
        private async System.Threading.Tasks.Task <bool> StartPlay(string deviceID, int startSector, int endSector)
        {
            try
            {
                bool result = false;
                if (string.IsNullOrEmpty(deviceID))
                {
                    LogMessage("Empty deviceID");
                    return(result);
                }

                // Stop the current stream
                mediaPlayer.Source = null;
                mediaPlayerElement.PosterSource = null;
                mediaPlayer.AutoPlay            = true;

                if (result == true)
                {
                    mediaPlayerElement.Visibility = Visibility.Collapsed;
                }
                else
                {
                    mediaPlayerElement.Visibility = Visibility.Visible;
                }

                string contentType = "audio/wav";
                mediaPlayer.Source = Windows.Media.Core.MediaSource.CreateFromStream(await CDTrackStream.Create(deviceID, startSector, endSector), contentType);
                mediaPlayer.Play();

                return(true);
            }
            catch (Exception ex)
            {
                LogMessage("Exception Playing: " + ex.Message.ToString());
            }
            return(false);
        }
Esempio n. 5
0
 private void Slider_PointerReleased(object sender, PointerRoutedEventArgs e)
 {
     if (PlaybackEngine.PlaybackEngine.Current.IsPlaying == null || PlaybackEngine.PlaybackEngine.Current.IsPlaying == false)
     {
         var player = new Windows.Media.Playback.MediaPlayer
         {
             Source = Windows.Media.Core.MediaSource.CreateFromUri(new Uri("ms-winsoundevent:Notification.Reminder"))
         };
         player.Volume      = Settings.Current.PlayerVolume / 100d;
         player.MediaEnded += (a, v) =>
         {
             player.Dispose();
         };
         player.Play();
     }
 }
        /// <summary>
        /// a media source was created for the current session (start rendering to ui)
        /// </summary>
        void OnSessionMediaSourceCreated(MiracastReceiverSession sender, MiracastReceiverMediaSourceCreatedEventArgs args)
        {
            //set flag
            currentConnectionTimeoutCancellation?.Cancel();

            //init mediaplayer
            currentPlayer = new UWPMediaPlayer()
            {
                Source = args.MediaSource,
                IsVideoFrameServerEnabled = false,
                AutoPlay         = true,
                RealTimePlayback = true
            };

            //call event
            CastStart?.Invoke(CurrentConnection.Transmitter.Name, currentPlayer);

            //start playback
            Log($"starting playback of {CurrentConnection.Transmitter.Name} ({CurrentConnection.Transmitter.MacAddress})");
            currentPlayer.Play();
        }
Esempio n. 7
0
            public void Play()
            {
                m_PlayThread = Unit.InvokeAsync(
                    () =>
                {
                    try
                    {
                        int iToneStep = 0;

                        m_audioTrack =
#if __ANDROID__
                            new Android.Media.AudioTrack
                            (
                                Android.Media.Stream.Music,
                                SampleRate,
                                Android.Media.ChannelOut.Mono,
                                Android.Media.Encoding.Pcm16bit,
                                2 * SampleRate,
                                Android.Media.AudioTrackMode.Stream
                            )
#elif __IOS__
                            AVFoundation.AVAudioPlayer.FromData(m_memory)
#elif WINDOWS_UWP
                            new Windows.Media.Playback.MediaPlayer
                        {
                            Source = Windows.Media.Core.MediaSource.CreateFromStream(
                                System.IO.WindowsRuntimeStreamExtensions.AsRandomAccessStream(m_memory),
                                "audio/wav")
                        }
#endif
                        ;
#if __ANDROID__
                        m_audioTrack.SetVolume((float)m_volume);
#elif __IOS__
                        m_audioTrack.Volume = (float)m_volume;
#elif WINDOWS_UWP
                        m_audioTrack.Volume = m_volume;
#endif


                        while (!cancellation.IsCancellationRequested && m_play_length-- > 0)
                        {
                            GenTone(iToneStep++);

#if __ANDROID__
                            m_audioTrack.Write(generatedSnd, 0, generatedSnd.Length);
#elif __IOS__
                            m_memory.AppendBytes(generatedSnd);
#elif WINDOWS_UWP
                            m_memory.Write(generatedSnd, 0, generatedSnd.Length);
#endif

                            if (iToneStep == 1)
                            {
                                m_audioTrack.Play();
                            }
                        }
                    }
                    catch (OutOfMemoryException e)
                    {
                        Log(e, LogImportance.E);
                    }
                    catch (Exception e)
                    {
                        Log(e, LogImportance.W);
                    }
                }, cancellation.Token
                    );
            }