當前位置: 首頁>>代碼示例>>C#>>正文


C# MediaElement.SetSource方法代碼示例

本文整理匯總了C#中Windows.UI.Xaml.Controls.MediaElement.SetSource方法的典型用法代碼示例。如果您正苦於以下問題:C# MediaElement.SetSource方法的具體用法?C# MediaElement.SetSource怎麽用?C# MediaElement.SetSource使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在Windows.UI.Xaml.Controls.MediaElement的用法示例。


在下文中一共展示了MediaElement.SetSource方法的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: StartMediaElement

        private async void StartMediaElement()
        {
            // To use AudioCategory.BackgroundCapableMedia:
            // * OnWindows 8 set MediaControl.PlayPressed, MediaControl.PausePressed,
            //   MediaControl.PlayPauseTogglePressed and MediaControl.StopPressed.
            // * On Windows 8.1 set SystemMediaTransportControls.ButtonPressed.
            systemControls = SystemMediaTransportControls.GetForCurrentView();
            systemControls.ButtonPressed += OnButtonPressed;
            systemControls.IsPlayEnabled = true;
            systemControls.IsPauseEnabled = true;
            systemControls.PlaybackStatus = MediaPlaybackStatus.Playing;

            mediaPlayer = new MediaElement();
            mediaPlayer.AudioCategory = AudioCategory.BackgroundCapableMedia;
            mediaPlayer.AutoPlay = true;
            mediaPlayer.CurrentStateChanged += OnCurrentStateChanged;
            this.Content = mediaPlayer;

            HttpClient client = new HttpClient();

            // Add custom headers or credentials.
            client.DefaultRequestHeaders.Add("Foo", "Bar");

            //Uri uri = new Uri("http://localhost/song.mp3?slow=1000&?bufferlength=100000&lastModified=true");
            Uri uri = new Uri("http://video.ch9.ms/ch9/70cc/83e17e76-8be8-441b-b469-87cf0e6a70cc/ASPNETwithScottHunter_high.mp4");

            HttpRandomAccessStream stream = await HttpRandomAccessStream.CreateAsync(client, uri);

            // If you need to use HttpClient, use MediaElement.SetSource() instead of MediaElement.Source.
            mediaPlayer.SetSource(stream, stream.ContentType);
        }
開發者ID:kiewic,項目名稱:MediaElementWithHttpClient,代碼行數:31,代碼來源:MainPage.xaml.cs

示例3: GetMediaElement

 public async Task GetMediaElement()
 {
     var element = new MediaElement();
     var elm = GetRandomElement();
     var stream = await elm.OpenAsync(FileAccessMode.Read);
     element.SetSource(stream, elm.ContentType);
     await PlayElement(element);
 }
開發者ID:jeppevammenkristensen,項目名稱:PunchlineDetector,代碼行數:8,代碼來源:MainPageViewModel.cs

示例4: 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

示例5: 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

示例6: SpeakText

        private async void SpeakText(MediaElement audioPlayer, string textToSpeak)
        {

            using (SpeechSynthesizer synthesizer = new SpeechSynthesizer())
            {
                SpeechSynthesisStream ttsStream = await synthesizer.SynthesizeTextToStreamAsync(textToSpeak);
                audioPlayer.SetSource(ttsStream, ""); // This starts the player because AutoPlay="True"

            }
        }
開發者ID:ernestoguimaraes,項目名稱:cortana,代碼行數:10,代碼來源:MainPage.xaml.cs

示例7: Speak

 public async void Speak(MediaElement audioPlayer, SpeechMessage speech)
 {
     var synth = new SpeechSynthesizer();
     var ttsStream = await synth.SynthesizeTextToStreamAsync(speech.Message);
     audioPlayer.SetSource(ttsStream, "");
     audioPlayer.CurrentStateChanged += async (object sender, Windows.UI.Xaml.RoutedEventArgs e) =>
     {
         await MainPage.Instance.SendResult(new ResultMessage(speech) { ResultId = (int)audioPlayer.CurrentState, Result = Enum.GetName(typeof(MediaElementState), audioPlayer.CurrentState) });
     };
 }
開發者ID:iot-alex,項目名稱:virtual-shields-universal,代碼行數:10,代碼來源:Speech.cs

示例8: 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

示例9: 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

示例10: 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

示例11: 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

示例12: 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

示例13: SpeakAsync

        public async Task SpeakAsync(string text)
        {
            var voice = SpeechSynthesizer.AllVoices
                .First(x => x.Gender.Equals(VoiceGender.Female) && x.Description.Contains("United States"));
            using (var speech = new SpeechSynthesizer { Voice = voice })
            {
                text = string.IsNullOrWhiteSpace(text) ? "There is no text to speak." : text;
                var stream = await speech.SynthesizeTextToStreamAsync(text);

                var media = new MediaElement { AutoPlay = true };
                media.SetSource(stream, stream.ContentType);
            }
        }
開發者ID:timothius2005,項目名稱:Template10,代碼行數:13,代碼來源:SpeechService.cs

示例14: 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

示例15: 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


注:本文中的Windows.UI.Xaml.Controls.MediaElement.SetSource方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。