locked
TranscodeProgress-Handling und TranscodeComplete-Handling in UWA mit MediaTranscoding RRS feed

  • Frage

  • Innerhalb einer Universal Windows App sollen Media-Files transcodiert werden. Die üblichen Formate werden ordnungsgemäß transcodiert, Ausnahmen werden durch entsprechende Fehlermeldungen behandelt. Was überhaupt nicht funktioniert, sind das TranscodeProgress-Handling sowie das ProgressComplete-Handling. In den im Folgenden aufgelisteten Routinen Convert_SOURCE_To_DEST, TranscodeProgress sowie TranscodeComplete ist der m. E. dafür verantwortliche Code gelb hervorgehoben. 

    Als Vorbild für das Programm wurde

    https://msdn.microsoft.com/windows/uwp/audio-video-camera/transcode-media-files

    herangezogen. Hat jemand eine Idee?

    Private Async Function Convert_SOURCE_To_DEST(ta As Double,

                                                         te As Double) _

                                                         As Task

            Dim pro As MediaEncodingProfile

            Dim res As Windows.Media.Transcoding.PrepareTranscodeResult

            Dim ope As IAsyncActionWithProgress(Of Double)

            Dim fol As Windows.Storage.StorageFolder

            Dim cod = New MediaTranscoder()

            Dim fop As New Windows.Storage.Pickers.FolderPicker

            Dim mus As FileProperties.MusicProperties

            Dim dur As Long

            Dim msg As String

            Try

                pro = MediaEncodingProfile.CreateWav(AUDIO_Qual) ' avoid warning

                Select Case DEST_Type

                    Case "WAV" : pro = MediaEncodingProfile.CreateWav(AUDIO_Qual)

                    Case "WMA" : pro = MediaEncodingProfile.CreateWma(AUDIO_Qual)

                    Case "MP3" : pro = MediaEncodingProfile.CreateMp3(AUDIO_Qual)

                    Case "M4a" : pro = MediaEncodingProfile.CreateM4a(AUDIO_Qual)

                    Case "AVI" : pro = MediaEncodingProfile.CreateAvi(VIDEO_Qual)

                    Case "MP4" : pro = MediaEncodingProfile.CreateMp4(VIDEO_Qual)

                    Case "WMV" : pro = MediaEncodingProfile.CreateWmv(VIDEO_Qual)

                End Select

                fop.ViewMode = PickerViewMode.List

                fop.SuggestedStartLocation = PickerLocationId.ComputerFolder

                fop.CommitButtonText = "Ziel-Ordner auswählen"

                fop.FileTypeFilter.Clear()

                fop.FileTypeFilter.Add(".WAV")

                fop.FileTypeFilter.Add(".WMA")

                fop.FileTypeFilter.Add(".MP3")

                fop.FileTypeFilter.Add(".M4a")

                fop.FileTypeFilter.Add(".AVI")

                fop.FileTypeFilter.Add(".MP4")

                fop.FileTypeFilter.Add(".WMV")

                fop.FileTypeFilter.Add(".MOV")

                fol = Await fop.PickSingleFolderAsync()

                mus = Await PICK_StorFil.Properties.GetMusicPropertiesAsync()

                dur = mus.Duration.Ticks

                If fol Is Nothing Then

                    MyMessage("")

                    cmd_Choice.Visibility = Visibility.Visible

                    Exit Function

                End If

                DEST_StorFil = Await _

                               fol.CreateFileAsync(PICK_StorFil.Name +

                               "." +

                               DEST_Type,

                               CreationCollisionOption.ReplaceExisting)

                cod.TrimStartTime = New TimeSpan(CLng(10000000 * ta))

                cod.TrimStopTime = New TimeSpan(dur - CLng(10000000 * te))

                cod.AlwaysReencode = True

                res = Await cod.PrepareFileTranscodeAsync(PICK_StorFil,

                                                          DEST_StorFil,

                                                          pro)

                If res.CanTranscode Then

                    ope = res.TranscodeAsync()

                    ope.Progress = New _

                    AsyncActionProgressHandler(Of Double) _

                    (AddressOf TranscodeProgress)

                    '--------------------------------------------------------------

                    ope.Completed = New _

                    AsyncActionWithProgressCompletedHandler(Of Double) _

                    (AddressOf TranscodeComplete)

                Else

                    msg = ""

                    msg = msg + "Fehler beim Transcodieren der Datei """

                    msg = msg + PICK_StorFil.Name

                    msg = msg + """: "

                    Select Case res.FailureReason

                        Case TranscodeFailureReason.CodecNotFound

                            ErrorCases(msg + "Codec nicht gefunden")

                        Case TranscodeFailureReason.InvalidProfile

                            ErrorCases(msg + "Ungültiges Profil")

                        Case TranscodeFailureReason.Unknown

                            ErrorCases(msg + "Unbekannte Ursache")

                        Case TranscodeFailureReason.None

                            ErrorCases(msg + "Keine Ursache")

                    End Select

                End If

                cmd_Choice.Visibility = Visibility.Visible

            Catch ex As Exception

                ErrorCases("Convert_SOURCE_To_DEST(" +

                                               SRC__Type +

                                               " ---> " +

                                               DEST_Type +

                                               "): " +

                                               ex.Message)

                cmd_Choice.Visibility = Visibility.Visible

            End Try

        End Function

        Private Sub TranscodeProgress(AsyncInfo As _

                                      IAsyncActionWithProgress(Of Double),

                                      prc As Double)

            MyMessage(CStr(prc))

        End Sub

        Private Sub TranscodeComplete(AsyncInfo As _

                                      IAsyncActionWithProgress(Of Double),

                                      sta As AsyncStatus)

            AsyncInfo.GetResults()

            Select Case AsyncInfo.Status

                Case AsyncStatus.Completed : MyMessage("Transcodierung erfolgt")

                Case AsyncStatus.Canceled : MyMessage("Transcodierung abgebrochen")

                Case AsyncStatus.Error : MyMessage("Transcodierung fehlerhaft")

                Case AsyncStatus.Started : MyMessage("Transcodierung gestartet")

            End Select

        End Sub


    • Bearbeitet Afanassij Sonntag, 24. Juli 2016 14:30 Korrektur
    Donnerstag, 30. Juni 2016 18:22