当前位置: 首页>>代码示例>>C#>>正文


C# MediaElement.Play方法代码示例

本文整理汇总了C#中Windows.UI.Xaml.Controls.MediaElement.Play方法的典型用法代码示例。如果您正苦于以下问题:C# MediaElement.Play方法的具体用法?C# MediaElement.Play怎么用?C# MediaElement.Play使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在Windows.UI.Xaml.Controls.MediaElement的用法示例。


在下文中一共展示了MediaElement.Play方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: StartTextToSpeech

        static public async Task StartTextToSpeech(string text)
        {
            if (!string.IsNullOrEmpty(text))
            {
                try
                {
                    if (_speech != null)
                    {
                        StopTextToSpeech();
                    }

                    var voice = GetSpeechVoice();
                    if (voice != null)
                    {
                        _speech = new SpeechSynthesizer();
                        _speech.Voice = voice;

                        SpeechSynthesisStream speechStream = await _speech.SynthesizeTextToStreamAsync(Utility.DecodeHtml(text));
                        _soundPlayer = new MediaElement();
                        _soundPlayer.SetSource(speechStream, speechStream.ContentType);
                        _soundPlayer.Play();
                    }
                }
                catch (Exception ex)
                {
                    AppLogs.WriteError("SpeechServices", ex);
                }
            }
        }
开发者ID:JerelStarks,项目名称:Thiroshiga,代码行数:29,代码来源:SpeechServices.cs

示例2: NowPlayingPageViewModel

        public NowPlayingPageViewModel()
        {
            App.Current.Suspending += Current_Suspending;
            App.Current.Resuming += Current_Resuming;
            SongHistory = new ObservableCollection<ShoutcastSongHistoryItem>();

            mediaElement = ((App)App.Current).MediaElement;

            PlayCommand = CommandManager.CreateCommand(() =>
            {
                if (mediaElement != null)
                    if (mediaElement.CurrentState != MediaElementState.Playing)
                    {
                        mediaElement.Play();
                        MediaControl.IsPlaying = true;
                    }
            });

            PauseCommand = CommandManager.CreateCommand(() =>
                {
                    if (mediaElement != null)
                        if (mediaElement.CurrentState != MediaElementState.Paused)
                        {
                            mediaElement.Pause();
                            MediaControl.IsPlaying = false;
                        }
                });
        }
开发者ID:Amrykid,项目名称:Hanasu,代码行数:28,代码来源:NowPlayingPageViewModel.cs

示例3: SongsList_Tapped

 private async void SongsList_Tapped(object sender, TappedRoutedEventArgs e)
 {
     MediaElement PlayMusic = new MediaElement();
     var _list = SongsList as ListView;
     var _song = (StorageFile)_list.SelectedItem;
     var stream = await _song.OpenAsync(FileAccessMode.Read);
     PlayMusic.SetSource(stream, _song.ContentType);
     PlayMusic.Play();
 }
开发者ID:jasonwun,项目名称:Rhys,代码行数:9,代码来源:MainPage.xaml.cs

示例4: Speak

        public async void Speak(string text)
        {
            var mediaElement = new MediaElement();
            var synth = new SpeechSynthesizer();
            var stream = await synth.SynthesizeTextToStreamAsync(text);

            mediaElement.SetSource(stream, stream.ContentType);
            mediaElement.Play();
        }
开发者ID:berlamont,项目名称:xamarin-forms-samples,代码行数:9,代码来源:TextToSpeech.cs

示例5: Fortune_Text_Click

 private async void Fortune_Text_Click(object sender, TappedRoutedEventArgs e)
 {
     MediaElement media = new MediaElement();
     string text = textBlockFortune.Text;
     SpeechSynthesizer synthesizer = new SpeechSynthesizer();
     SpeechSynthesisStream stream = await synthesizer.SynthesizeTextToStreamAsync(text + ", God bless America");
     media.SetSource(stream, stream.ContentType);
     media.IsLooping = true;
     media.Play();
 }
开发者ID:man1utdfan,项目名称:Manto,代码行数:10,代码来源:MainPage.xaml.cs

示例6: PlayAsync

        public async Task PlayAsync(Stream speechStream, string contentFormat)
        {
            if (speechStream == null) throw new ArgumentNullException(nameof(speechStream));
            if (contentFormat == null) throw new ArgumentNullException(nameof(speechStream));

            var media = new MediaElement();
            media.SetSource(speechStream.AsRandomAccessStream(), contentFormat);
            media.Play();

            await Task.CompletedTask;
        }
开发者ID:evgri243,项目名称:pubic-demos,代码行数:11,代码来源:SpeechPlayer.cs

示例7: Speak

		public async void Speak(string text)
		{
			SpeechSynthesizer synthesizer = new SpeechSynthesizer();
			SpeechSynthesisStream stream = await synthesizer.SynthesizeTextToStreamAsync(text);
			MediaElement media = new MediaElement();
			media.AutoPlay = true;
			media.SetSource(stream, stream.ContentType);
			media.Play();


		}
开发者ID:marignygrisgris,项目名称:QuickDev,代码行数:11,代码来源:TextToSpeechWindows.cs

示例8: PlaySound

 private void PlaySound(MediaElement SoundElement)
 {
     try
     {
         SoundElement.Play();
     }
     catch
     {
         System.Diagnostics.Debug.WriteLine("Problem playing sound: " + SoundElement.ToString());
     }
 }
开发者ID:klim3d,项目名称:VirtualGym_1.0,代码行数:11,代码来源:RehabilitationMode.xaml.cs

示例9: Play

        public async Task<bool> Play(string fileName)
        {
            var var_assets = await Package.Current.InstalledLocation.GetFolderAsync("Music");
            var var_file = await var_assets.GetFileAsync(fileName);
            var var_stream = await var_file.OpenAsync(FileAccessMode.Read);

            MediaElement m = new MediaElement();
            m.SetSource(var_stream, var_file.ContentType);
            m.Play();

            return true;
        }
开发者ID:NatuLearn,项目名称:NumbersGame,代码行数:12,代码来源:AudioService.cs

示例10: Speak

        public async void Speak(string text)
        {
            MediaElement mediaElement = new MediaElement();

            var synth = new Windows.Media.SpeechSynthesis.SpeechSynthesizer();

            SpeechSynthesisStream stream = await synth.SynthesizeTextToStreamAsync("Hello World");

            mediaElement.SetSource(stream, stream.ContentType);
            mediaElement.Play();
            await synth.SynthesizeTextToStreamAsync(text);
        }
开发者ID:RickySan65,项目名称:xamarin-forms-samples,代码行数:12,代码来源:TextToSpeech.cs

示例11: Play

        public async Task Play( string fileName)
        {
            var packageLocation = Windows.ApplicationModel.Package.Current.InstalledLocation;
            var assetsFolder = await packageLocation.GetFolderAsync("assets");
            var soundsFolder = await assetsFolder.GetFolderAsync("sounds");
            StorageFile myAudio = await soundsFolder.GetFileAsync(fileName);

            _mediaElement = new MediaElement();
            
            var stream = await myAudio.OpenAsync(FileAccessMode.Read);
            _mediaElement.SetSource(stream, myAudio.ContentType);

            _mediaElement.Play();
        }
开发者ID:derikwhittaker,项目名称:Memory,代码行数:14,代码来源:AudioManager.cs

示例12: Play

        public async Task Play(string fileName)
        {
            var packageLocation = Windows.ApplicationModel.Package.Current.InstalledLocation;
            var assetsFolder = await packageLocation.GetFolderAsync("Assets");

            var myAudio = await assetsFolder.GetFileAsync(fileName);
            if (myAudio != null)
            {
                var stream = await myAudio.OpenAsync(Windows.Storage.FileAccessMode.Read);
                MediaElement snd = new MediaElement();
                snd.SetSource(stream, myAudio.ContentType);
                snd.Play();
            }
        }  
开发者ID:aadennis,项目名称:SpeakingNumbers,代码行数:14,代码来源:SpeakNumbersViewModel.cs

示例13: Play

 public void Play()
 {
     Task task = Task.Run(async () => {
         StorageFolder location = Windows.ApplicationModel.Package.Current.InstalledLocation;
         StorageFolder folder = await location.GetFolderAsync("CountDown");
         StorageFolder subfolder = await folder.GetFolderAsync("Assets");
         StorageFile file = await subfolder.GetFileAsync("Ding.wav");
         Uri path = new Uri(file.Path, UriKind.Absolute);
         MediaElement mediaElement = new MediaElement()
         {
             AutoPlay = false,
             Source = path,
         };
         mediaElement.Play();
     });
 }
开发者ID:Qerts,项目名称:TestOctopus2,代码行数:16,代码来源:SoundManipulation.cs

示例14: Speak

		// http://msdn.microsoft.com/en-us/library/windowsphone/develop/jj207057(v=vs.105).aspx
		public async void Speak(string text)
		{
			SpeechSynthesizer synth = new SpeechSynthesizer();

            try
            {
                var stream = await synth.SynthesizeTextToStreamAsync(text);

                var mediaElement = new MediaElement();
                mediaElement.SetSource(stream, stream.ContentType);
                mediaElement.Play();
            }
            catch (Exception pe) {
                Debug.WriteLine("couldn't play voice " + pe.Message);
            }
		}
开发者ID:RickySan65,项目名称:xamarin-forms-samples,代码行数:17,代码来源:TextToSpeech_WinPhone81.cs

示例15: SpeakButton_Click

       // SpeechRecognitionEngine sRecognize = new SpeechRecognitionEngine();


      
        private async void SpeakButton_Click(object sender, RoutedEventArgs e)
        {
            // The media object for controlling and playing audio.
            MediaElement mediaElement = new MediaElement();

            // The object for controlling the speech-synthesis engine (voice).
            SpeechSynthesizer synth = new Windows.Media.SpeechSynthesis.SpeechSynthesizer();



            // Generate the audio stream from plain text.
            SpeechSynthesisStream stream = await synth.SynthesizeTextToStreamAsync(txtText.Text);

            // Send the stream to the media object.
            mediaElement.SetSource(stream, stream.ContentType);
            mediaElement.Play();
        }
开发者ID:TUM-FAF,项目名称:FAF-121-Barbaros-Nicolae,代码行数:21,代码来源:MainPage.xaml.cs


注:本文中的Windows.UI.Xaml.Controls.MediaElement.Play方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。