0

i have 2 forms (form1) and (form2), form2 has media player and combobox to choose video this is the code:

Public Class Form2
  Private Sub ComboBox1_SelectedIndexChanged(sender As Object, e As EventArgs) Handles ComboBox1.SelectedIndexChanged
    If ComboBox1.SelectedItem = "Video 1" Then    
      On Error Resume Next
      IO.File.WriteAllBytes(IO.Path.GetTempPath & "\Video 1.mp4", My.Resources.Video_2)
      AxWindowsMediaPlayer1.URL = IO.Path.GetTempPath & "\Video 1.mp4"
      IO.File.Delete(IO.Path.GetTempPath & "\Video 1.mp4")
    End If

    If ComboBox1.SelectedItem = "Video 2" Then
      On Error Resume Next
      IO.File.WriteAllBytes(IO.Path.GetTempPath & "\Video 2.mp4", My.Resources.Video_2)
       AxWindowsMediaPlayer1.URL = IO.Path.GetTempPath & "\Video 2.mp4"
       IO.File.Delete(IO.Path.GetTempPath & "\Video 2.mp4")
    End If

    If ComboBox1.SelectedItem = "Video 3" Then
      On Error Resume Next
      IO.File.WriteAllBytes(IO.Path.GetTempPath & "\Video 3.mp4", My.Resources.Video_3)
      AxWindowsMediaPlayer1.URL = IO.Path.GetTempPath & "\Video 3.mp4"
      IO.File.Delete(IO.Path.GetTempPath & "\Video 3.mp4")
    End If
  End Sub
End Class

this code works fine until i changed (form1) to be parent and (form2) to be child with this code:

Private Sub Form1_Load(sender As Object, e As EventArgs) Handles MyBase.Load
  Form2.StartPosition = FormStartPosition.Manual
  Form2.Left = 105
  Form2.Top = 50
  Form2.MdiParent = Me
End Sub

video isn't viewed right (only part of it) as if the video is larger than media player screen also full screen mode isn't working at all. this is another trial with no progress:

If ComboBox1.SelectedItem = "Video 1" Then
  Dim b As Byte() = My.Resources.Video_1
  Dim TheFIlePath As String = "Video 1.mp4"
  Dim TempFile As IO.FileStream = IO.File.Create(TheFIlePath)
  TempFile.Write(b, 0, b.Length)
  TempFile.Close()
  AxWindowsMediaPlayer1.URL = (TheFIlePath)
End If

i tried both true and false for stretchtofit also tried with (Try and Catch exception) like this:

If ComboBox1.SelectedItem = "Video 1" Then

    Try
        AxWindowsMediaPlayer1.URL = "D:\40.mp4"
    Catch ex As Exception
        MsgBox(ex.Message)
    End Try

End If

with no success, this is the video screenshot when it is playing well:

enter image description here

and this is when form2 became mdi child: enter image description here

GME
  • 156
  • 2
  • 2
  • 16
  • Maybe [AxWindowsMediaPlayer.stretchToFit](https://learn.microsoft.com/en-us/windows/win32/wmp/axwmplib-axwindowsmediaplayer-stretchtofit--vb-and-c). Also, you shouldn't use this `On Error Resume Next`. Use the [Try..Catch](https://learn.microsoft.com/en-us/dotnet/visual-basic/language-reference/statements/try-catch-finally-statement) block and handle the exceptions if any. Also, adding video files to `Resources` is not a good idea. –  Apr 30 '20 at 22:23
  • please take a look at the last part of the question after editing – GME May 01 '20 at 02:21
  • Maybe a screen shot of the problem might help in this case. – LarsTech May 01 '20 at 02:26
  • done, please look at the last part of the question – GME May 01 '20 at 02:44
  • Use the @ sign in comments before a user name to notify them you are replying to them. MDI child forms don't play well when you remove the border. Not sure that's 100% the issue here, but put the default border back. Also, MDI is old technology. Consider going back to a single form with a panel that you just add the video to it. – LarsTech May 01 '20 at 02:53
  • Sorry, use LarsTech's instruction to notify someone. Now hosting the control in MDI child won't work. I believe you have already got that **Catastrophic Exception** when you try to dock or resize the WMP. What is the point of implementing the MDI design? maybe we could suggest alternatives if you could clarify what you are trying to achieve. Do you need to load multiple files or multiple different Forms? What about the borderless Form? Do you need to move the borderless Form. –  May 01 '20 at 16:41
  • @LarsTech, the problem exists after returning the default border, i think the panel idea may work with me after some modifications, thanks – GME May 01 '20 at 19:59
  • @JQSOFT, i have a main form (parent) and multiple child forms opens in it, each one of them has a different function, one of them was the form that opens stored videos, i could try the panel idea proposed by LarsTech on this form only but i can't change the design for whole project as it is too big, please explain me more about what you said (adding video files to Resources is not a good idea). – GME May 01 '20 at 20:06
  • Yes Lars's is a good idea. Well, Embed some video files and check the size of the output (exe file). Its OK if the video file is just a small one for a splash screen for example. Otherwise, load them from the disk. –  May 01 '20 at 20:25

1 Answers1

1

After a lot of search, i found that windows media player cannot be played full screen in mdi child form.

so instead of using mdi child form, i replaced it with a panel and AxWindowsMediaPlayer was added, the fullscreen property is now working fine and the video is scaled fine.

GME
  • 156
  • 2
  • 2
  • 16