Example #1
0
        //粤语发音
        private async void Voice_Click(object sender, RoutedEventArgs e)
        {
            TextToVoice temp  = new TextToVoice();
            Stream      voice = await temp.ReadText(Input.Text);

            InMemoryRandomAccessStream ras = new InMemoryRandomAccessStream();
            await voice.CopyToAsync(ras.AsStreamForWrite());

            await ras.FlushAsync();

            ras.Seek(0);
            MyMediaPlayer.SetSource(ras, "");
        }
Example #2
0
        async private System.Threading.Tasks.Task SetLocalMedia()
        {
            var openPicker = new Windows.Storage.Pickers.FileOpenPicker();

            openPicker.FileTypeFilter.Add(".mp4");
            openPicker.FileTypeFilter.Add(".mp3");

            var file = await openPicker.PickSingleFileAsync();

            // mediaPlayer is a MediaElement defined in XAML
            if (file != null)
            {
                var stream = await file.OpenAsync(Windows.Storage.FileAccessMode.Read);

                MyMediaPlayer.SetSource(stream, file.ContentType);

                MyMediaPlayer.Play();
            }
        }
        private async void SoundGridView_Drop(object sender, DragEventArgs e)
        {
            if (e.DataView.Contains(StandardDataFormats.StorageItems))
            {
                var items = await e.DataView.GetStorageItemsAsync();

                if (items.Any())
                {
                    StorageFile storageFile = items[0] as StorageFile;
                    var         contentType = storageFile.ContentType;

                    if (contentType == "audio/mpeg" || contentType == "audio/wav")
                    {
                        MyMediaPlayer.SetSource(await storageFile.OpenAsync(FileAccessMode.Read), contentType);
                        MyMediaPlayer.Play();
                        PlayPauseButton.Content = "\xE769";
                    }
                }
            }
        }
Example #4
0
        private async void DownLoadButton_Click(object sender, RoutedEventArgs e)
        {
            Uri uri = new Uri(MyBox.Text);

            MyMediaPlayer.Source = uri;
            string FileName = System.IO.Path.GetFileName(uri.LocalPath);


            var httpClient   = new HttpClient();
            var httpResponse = new Windows.Web.Http.HttpResponseMessage();
            var file         = await KnownFolders.MusicLibrary.CreateFileAsync(FileName, CreationCollisionOption.ReplaceExisting);

            string httpResponseBody = "";

            try
            {
                httpResponse = await httpClient.GetAsync(uri);

                httpResponse.EnsureSuccessStatusCode();
                httpResponseBody = await httpResponse.Content.ReadAsStringAsync();

                var sourceStream = await httpResponse.Content.ReadAsInputStreamAsync();

                using (var destinationStream = await file.OpenAsync(FileAccessMode.ReadWrite))
                {
                    using (var destinationOutputStream = destinationStream.GetOutputStreamAt(0))
                    {
                        await RandomAccessStream.CopyAndCloseAsync(sourceStream, destinationStream);
                    }
                }
                var stream = await file.OpenAsync(Windows.Storage.FileAccessMode.Read);

                MyMediaPlayer.SetSource(stream, file.ContentType);
                MyMediaPlayer.Play();
            }
            catch { }
        }