Main Menu

Chủ Nhật, 30 tháng 10, 2016

WINDOWS STORE APPS - BUỔI 5

WINDOWS STORE APPS - BUỔI 5

1. Bài Tập 1 . Convert Video


Thêm Video vào project :
* Chỉnh properties cho MediaElement :
* Run Apps :
* Chỉnh sửa Giao diện :

*
*
*
* Viết sự kiện click cho button PickFile :
* Thêm 1 textBlock hiển thị tiến trình :
* Viết Code cho button Transcode :
private async void Transcode_Click(object sender, RoutedEventArgs e)
        {
            string outputFileName = NewFileName.Text;
            if (string.IsNullOrEmpty(outputFileName))
            {
                var ms = new MessageDialog("Please type new File Name.");
                ms.ShowAsync();
                return;
            }
          // Clear messages
            StatusMessage.Text = "";
            Transcode.IsEnabled = false;
            NewFileName.IsEnabled = false;
            InputVideo.Pause();
            const VideoEncodingQuality videoEncodingProfile = VideoEncodingQuality.Wvga;
            _profile = MediaEncodingProfile.CreateMp4(videoEncodingProfile);
            try
            {
                if (_inputFile != null)
                {
                    _outputFile = await KnownFolders.VideosLibrary.CreateFileAsync(outputFileName, CreationCollisionOption.ReplaceExisting);
                    var preparedTranscodeResult = await _transcoder.PrepareFileTranscodeAsync(_inputFile, _outputFile, _profile);
                    _transcoder.VideoProcessingAlgorithm = MediaVideoProcessingAlgorithm.Default;
                    if (preparedTranscodeResult.CanTranscode)
                    {
                        _cts = new CancellationTokenSource();
                        var progress = new Progress<double>(TranscodeProgress);
                        await preparedTranscodeResult.TranscodeAsync().AsTask(_cts.Token, progress);
                        TranscodeComplete();
                    }
                    else
                    {
                        TranscodeFailure(preparedTranscodeResult.FailureReason);
                    }
                }
            }
            catch (TaskCanceledException)
            {
                OutputText("");
                TranscodeError("Transcode Canceled");
            }
            catch (Exception exception)
            {
                TranscodeError(exception.Message);
            }

        }

* Thêm hàm TranscodeProgress(double percent) : => Hiển thị progressbar
** Thêm 2 textBlock vào giao diện : đặt names = outputPath và StatusMessage
* Thêm hàm TranscodeComplete() :
* Thêm hàm TranscodeFailure(TranscodeFailureReason reason)

* Thêm 3 Hàm cuối cùng :
*Chỉnh đường dẫn cho Video :
* Run Apps :
*

Không có nhận xét nào:

Đăng nhận xét