Selbst programmierter Media Player öffnet Dateien von außen nicht

  • VB.NET

Es gibt 8 Antworten in diesem Thema. Der letzte Beitrag () ist von thefiloe.

    Selbst programmierter Media Player öffnet Dateien von außen nicht

    Hallo liebe Comm

    ich habe ein Problem mit einem Media Player, den ich gecodet habe. Das Problem ist wie folgt:
    Wenn ich eine .mp3 oder andere Media Dateien öffne (Musik) erscheint dieser Dialog:




    Weiß jemand warum?

    Das ist der Code den ich verwende:

    [Der Code] (Sry muss den so posten weil er beim Absenden wieder in eine Zeile rückt...)

    If My.Application.CommandLineArgs.Count > 0 Then
    Dim v As Array
    Dim mypath As String
    Dim commandlineargs As String = Environment.CommandLine
    v = Split(commandlineargs, """ ")
    mypath = v(1)
    AxWindowsMediaPlayer1.URL = (mypath)
    End If
    [Ende]

    Wenn jemand den Fehler weiß bitte melden :)




    Liebe Grüße

    Dieser Beitrag wurde bereits 3 mal editiert, zuletzt von „Shaymin123[CRI09]“ ()

    "Selbstprogrammiert"
    a) Ist an nem Mediaplayercontrol mit nem Designer auf ne Form ziehen nix "selbst" dran
    b) Verwend was anständiges


    Opensource Audio-Bibliothek auf github: KLICK, im Showroom oder auf NuGet.
    Zur Frage b (Was anderes), da haste einiges zur Auswahl ;D
    Ich verwende bei Player-Angelegenheiten meine dafür erstellte Klasse:

    Spoiler anzeigen

    VB.NET-Quellcode

    1. Public Class MediaPlayer
    2. Private Declare Function mciSendString Lib "Winmm.dll" Alias "mciSendStringA" (ByVal lpszCommand As String, ByVal lpszReturnString As String, ByVal cchReturn As Integer, ByVal hwndCallback As IntPtr) As Integer
    3. Private strFileName As String
    4. Private ctrWindow As Control
    5. Private strAlias As String = "video1"
    6. Private bOpened As Boolean = False
    7. Private bPlaying As Boolean = False
    8. Private iVolume As Integer
    9. Private iSpeed As Integer
    10. Public Property Filename() As String
    11. Get
    12. Return strFileName
    13. End Get
    14. Set(ByVal strValue As String)
    15. strFileName = strValue
    16. End Set
    17. End Property
    18. Public Property MediaWindow() As Control
    19. Get
    20. Return ctrWindow
    21. End Get
    22. Set(ByVal ctrValue As Control)
    23. ctrWindow = ctrValue
    24. End Set
    25. End Property
    26. Public ReadOnly Property Status() As String
    27. Get
    28. Dim strStatus As String = Space(128)
    29. If mciSendString("STATUS " & strAlias & " MODE", strStatus, Len(strStatus), IntPtr.Zero) = 0 Then
    30. strStatus = Replace(Trim(strStatus), Chr(0), "")
    31. Return strStatus
    32. End If
    33. End Get
    34. End Property
    35. Public Property Volume() As Integer
    36. Get
    37. Return iVolume
    38. End Get
    39. Set(ByVal Value As Integer)
    40. iVolume = Value
    41. mciSendString("SETAUDIO " & strAlias & " VOLUME TO " & iVolume, 0&, 0, IntPtr.Zero)
    42. End Set
    43. End Property
    44. Public Property Speed() As Integer
    45. Get
    46. Return iSpeed
    47. End Get
    48. Set(ByVal Value As Integer)
    49. iSpeed = Value
    50. mciSendString("SET " & strAlias & " SPEED " & iSpeed, 0&, 0, IntPtr.Zero)
    51. End Set
    52. End Property
    53. Public ReadOnly Property Opened() As Boolean
    54. Get
    55. Return bOpened
    56. End Get
    57. End Property
    58. Public Function Open() As Boolean
    59. If bOpened = False And mciSendString("OPEN """ & strFileName & """ alias " & strAlias & " TYPE MPEGVIDEO PARENT " & ctrWindow.Handle.ToString & " STYLE CHILD", 0&, 0, IntPtr.Zero) = 0 Then
    60. bOpened = True
    61. End If
    62. Return bOpened
    63. End Function
    64. Public Function Close() As Boolean
    65. If bOpened = True And mciSendString("CLOSE " & strAlias, 0&, 0, IntPtr.Zero) = 0 Then
    66. bOpened = False
    67. End If
    68. Return Not bOpened
    69. End Function
    70. Public Function Play() As Boolean
    71. If bPlaying = False And mciSendString("PLAY " & strAlias, 0&, 0, IntPtr.Zero) = 0 Then
    72. bPlaying = True
    73. End If
    74. Return bPlaying
    75. End Function
    76. Public Function [Stop]() As Boolean
    77. If bOpened = True And mciSendString("STOP " & strAlias, 0&, 0, IntPtr.Zero) = 0 Then
    78. mciSendString("SEEK " & strAlias & " TO START", 0&, 0, IntPtr.Zero)
    79. bPlaying = False
    80. End If
    81. Return Not bPlaying
    82. End Function
    83. Public Function Pause() As Boolean
    84. If bPlaying = True And mciSendString("PAUSE " & strAlias, 0&, 0, IntPtr.Zero) = 0 Then
    85. bPlaying = False
    86. End If
    87. Return Not bPlaying
    88. End Function
    89. Public Function Fit() As Boolean
    90. Dim strSize As String = Space(128)
    91. If mciSendString("WHERE " & strAlias & " source", strSize, Len(strSize), IntPtr.Zero) = 0 Then
    92. Dim coords() As String = Split(Trim(strSize), " ")
    93. Dim Size As New Size(CInt(coords(2)), CInt(coords(3)))
    94. If Not Size.IsEmpty Then
    95. Dim dblRatio As Double
    96. dblRatio = ctrWindow.Width / Size.Width
    97. If Size.Height * dblRatio > ctrWindow.Height Then
    98. dblRatio = ctrWindow.Height / Size.Height
    99. End If
    100. Dim iWidth As Integer = CInt(Size.Width * dblRatio)
    101. Dim iHeight As Integer = CInt(Size.Height * dblRatio)
    102. Dim iLeft As Integer = CInt((ctrWindow.Width - iWidth) / 2)
    103. Dim iTop As Integer = CInt((ctrWindow.Height - iHeight) / 2)
    104. Return (mciSendString("PUT " & strAlias & " WINDOW AT " & CStr(iLeft) & " " & CStr(iTop) & " " & CStr(iWidth) & " " & CStr(iHeight), 0&, 0, IntPtr.Zero) = 0)
    105. Else
    106. Return False
    107. End If
    108. End If
    109. End Function
    110. Public Function GetTotalTime() As Integer
    111. Dim strTime As String = Space(128)
    112. mciSendString("SET " & strAlias & " TIME FORMAT MS", 0&, 0, IntPtr.Zero)
    113. If mciSendString("STATUS " & strAlias & " LENGTH", strTime, Len(strTime), IntPtr.Zero) = 0 Then
    114. Return CInt(Trim(strTime))
    115. End If
    116. Return 0
    117. End Function
    118. Public Function GetPosition() As Integer
    119. Dim strPos As String = Space(128)
    120. mciSendString("SET " & strAlias & " TIME FORMAT MS", 0&, 0, IntPtr.Zero)
    121. If mciSendString("STATUS " & strAlias & " POSITION", strPos, Len(strPos), IntPtr.Zero) = 0 Then
    122. Return CInt(Trim(strPos))
    123. End If
    124. Return 0
    125. End Function
    126. Public Function SetPosition(ByVal Pos As Integer) As Boolean
    127. Dim strPos As String = Space(128)
    128. If bPlaying = True Then
    129. If mciSendString("PLAY " & strAlias & " FROM " & Pos, 0&, 0, IntPtr.Zero) = 0 Then
    130. Return True
    131. End If
    132. Else
    133. If mciSendString("SEEK " & strAlias & " TO " & Pos, 0&, 0, IntPtr.Zero) = 0 Then
    134. Return True
    135. End If
    136. End If
    137. Return False
    138. End Function
    139. Public Function GetHMS(ByVal ms As Integer) As String
    140. Dim intSeconds As Integer
    141. Dim intMinutes As Integer
    142. Dim intHours As Integer
    143. intSeconds = ms / 1000
    144. If (intSeconds > 3600) Or (intSeconds = 3600) Then
    145. intHours = Int(intSeconds / 3600)
    146. intSeconds = intSeconds - (intHours * 3600)
    147. Else
    148. intHours = 0
    149. End If
    150. If (intSeconds > 60) Or (intSeconds = 60) Then
    151. intMinutes = Int(intSeconds / 60)
    152. intSeconds = intSeconds - (intMinutes * 60)
    153. Else
    154. intMinutes = 0
    155. End If
    156. Dim Time As Date = CStr(intHours) & ":" & CStr(intMinutes) & ":" & CStr(intSeconds)
    157. Return CStr(Time)
    158. End Function
    159. End Class


    Einfach dazukopieren und ansprechen. Für Videos einfach ne PicBox verwenden ;D

    mfg

    gfc

    Dieser Beitrag wurde bereits 1 mal editiert, zuletzt von „gfcwfzkm“ ()

    Muss ich das in einer neuen Funktion zu hauen oder in den Form1.vb setzen?

    EDIT: Habs als Modul einfefügt

    Habe 2 Fehler:


    Warnung 1 Von der Eigenschaft "Status" wird nicht in allen Codepfaden ein Wert zurückgegeben. Wenn das Ergebnis verwendet wird, kann zur Laufzeit eine NULL-Verweisausnahme auftreten. C:\Users\Twilight Sparkle\documents\visual studio 2010\Projects\AMP4W\AMP4W\MediaPlayer.vb 37 13 AMP4W

    Warnung 2 Die Fit-Funktion gibt nicht für alle Codepfade einen Wert zurück. Fehlt eine Return-Anweisung? C:\Users\Twilight Sparkle\documents\visual studio 2010\Projects\AMP4W\AMP4W\MediaPlayer.vb 136 9 AMP4W

    Dieser Beitrag wurde bereits 1 mal editiert, zuletzt von „Shaymin123[CRI09]“ ()

    @gfcwfzkm: Kannst Du bitte um Deinen Code herum einen Expander bauen :?:

    Shaymin123[CRI09] schrieb:

    Habe 2 Fehler:
    Lesen und verstehen

    VB.NET-Quellcode

    1. Public Function xxx(ByVal value As Integer) As Integer
    2. Select Case value
    3. Case 1 : Return 1
    4. Case 2 : Return 2
    5. Case 3 : Return 3
    6. Case Else
    7. ' nix
    8. End Select
    9. ' nix
    10. End Function
    Falls Du diesen Code kopierst, achte auf die C&P-Bremse.
    Jede einzelne Zeile Deines Programms, die Du nicht explizit getestet hast, ist falsch :!:
    Ein guter .NET-Snippetkonverter (der ist verfügbar).
    Programmierfragen über PN / Konversation werden ignoriert!
    Am besten verwendest du eine Bibliothek wie die Bass.dll.
    Bei der mciSendString Methode hast du nämlich recht wenig Möglichkeiten und wirklich ne Ganze Bibliothek ist für dich viel zu viel Arbeit.


    Opensource Audio-Bibliothek auf github: KLICK, im Showroom oder auf NuGet.