none
Specifying which monitor for video to play on

    Pregunta

  • Greets

    I have an application I am working on and have a projector connected and working as the second monitor.

    I would like to setup my application to play, in fullscreen mode (using Windows Media Player) on the second monitor.

    I have found many hits on this topic and not sure the right way to go.

    I would like the application to then close WMP after the end of the one minute video clip

    I am using Visual Basic 2008.

    Thanks in advance!

    Paul
    jueves, 14 de enero de 2010 1:16

Respuestas

  • I find this line is not needed the video plays when you set the url


            'Tell the WindowsMediaPlayer control on the form to play the video
            NewForm.AxWindowsMediaPlayer2.Ctlcontrols.play()

    New Code :

        
    Private Sub Button1_Click _
        (
    ByVal sender As System.Object, _
         
    ByVal e As System.EventArgs) Handles Button1.Click

            
    ' Create a copy of frmVideo
            Dim NewForm As New frmVideo

            
    'Set the start Position of the new form to Manual
            NewForm.StartPosition = FormStartPosition.Manual

            
    'Set the Screen coordinates of the new form using
            'the bounds of the Second Display ( bounds being the boundry or rectangle it uses )
            NewForm.Location = _
            
    New Point(Screen.AllScreens(1).Bounds.X, Screen.AllScreens(1).Bounds.Y)

            
    'Set what video to play on the copy of frmVideo
            NewForm.AxWindowsMediaPlayer2.URL = "D:\r2d2\7\leiaHires2.wmv"

            'Show the new form we created from frmVideo
            NewForm.Show()

        
    End Sub

    New Code for frmVideo :

    Public Class frmVideo
        
    Private Sub AxWindowsMediaPlayer2_PlayStateChange(ByVal sender As System.Object, ByVal e As AxWMPLib._WMPOCXEvents_PlayStateChangeEvent) Handles AxWindowsMediaPlayer2.PlayStateChange

            
    If AxWindowsMediaPlayer2.playState = WMPLib.WMPPlayState.wmppsPlaying Then
                AxWindowsMediaPlayer2.fullScreen = True
            End If

            If AxWindowsMediaPlayer2.playState = _
            WMPLib.WMPPlayState.wmppsStopped _
            
    Or _
            AxWindowsMediaPlayer2.playState = _
            WMPLib.WMPPlayState.wmppsMediaEnded 
    Then

                Me.Close()

            
    End If

        End Sub

    End
     Class


    Coding4fun Be a good forum member mark posts that contain the answers to your questions or those that are helpful
    Please format the code in your posts with the button . Makes it easier to read .
    domingo, 17 de enero de 2010 4:54
  • Start a new project and use just the last code I posted . On the first form put a button and the button code I posted . Add a new form call it frmVideo , add a windows media player control to it and name it AxWindowsMediaPlayer2 , set the dock property of the media player control to fill and use the second bit of code I posted . If that works then maybe there is something else stopping it from working . Like I said on my setup with my Netbook and a 7" touchscreen I used that code and it works good .
    Coding4fun Be a good forum member mark posts that contain the answers to your questions or those that are helpful
    Please format the code in your posts with the button . Makes it easier to read .
    domingo, 17 de enero de 2010 5:15
  • SOLVED!

    I compared the frmVideo settings side by side with the sample you made.

    Once I set the WindowsState to Normal in the frmVideo setting, it started to work!

    More in a bit...I want to verify all is well on the test laptop, then try it on R2's netbook.
    domingo, 17 de enero de 2010 5:41

Todas las respuestas

  • Dim x() As Screen = Screen.AllScreens

    Will get the screens on your computer . Use that to get the bounds of each screen and locate the media player on the second screen then maximize it . I think it should work depending on how your screens are set up .

    Coding4fun Be a good forum member mark posts that contain the answers to your questions or those that are helpful
    Please format the code in your posts with the button . Makes it easier to read .
    jueves, 14 de enero de 2010 7:42
  • I'll try that !

    Paul
    viernes, 15 de enero de 2010 1:49
  • Ok....a few stumbles....

    How do I get vb 2008 to span across the two monitors?

    I already use WMP to play MP3s, so I am guessing I need to create a second WMP control to play the video

    Then, how do I tell THAT to go into the right (display2) ?

    Thanks
    viernes, 15 de enero de 2010 4:22
  • How is your system set up is it set up to extend your desktop onto the second display ? If so just set the location of the second form so the left coordinate is on the second display .
    Coding4fun Be a good forum member mark posts that contain the answers to your questions or those that are helpful
    Please format the code in your posts with the button . Makes it easier to read .
    viernes, 15 de enero de 2010 4:50
  • You might give this a try


        
    Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
            
    For Each S As Screen In Screen.AllScreens
                
    If Not S.Equals(Screen.PrimaryScreen) Then
                    Me.Location = New Point(S.Bounds.X, 0)
                
    End If
            Next
        End Sub

    Coding4fun Be a good forum member mark posts that contain the answers to your questions or those that are helpful
    Please format the code in your posts with the button . Makes it easier to read .
    viernes, 15 de enero de 2010 5:00
  • Hi

    I appreciate your replies.

    Yes, I have my notebook set to use the projector as monitor 2.  However, vb2008 is on the primary monitor...I do not see a way to "spread" it across both screens.  Just one or the other.

    The path for the video I want to play is, for example, "D:\video\test.avi"

    I am working with some code that was upgraded from VB6 to interpet gamepad button presses.

    Right now, I want button 7 to launch the WMP into the secondary monitor, full screen, play once

      

    If

     

    IsButtonPressed(buttonStates(7)) Then

    AxWindowsMediaPlayer2   <---  Trying to figure out what to do beyond here.  Can I set WMP to set the monitor it plays video? 

    Also not sure how the path would go.

    Did I mention I'm still a noob?   :-)

    I did create the AxWindowsMediaPlayer2 control on the form and set Visible = False (so as not to appear on the form)

    viernes, 15 de enero de 2010 5:09
  • I figured out how to play the WMV (its not an AVI, my bad)

    AxWindowsMediaPlayer2.URL =

    "d:\video\test.wmv"

    Problem is, I have audio, no video....which makes sense, I have figured that out, much less on the second display

    viernes, 15 de enero de 2010 5:50
  • You probably should use a second form and put a MediaPlayer control docked on it and put it on the second monitor . Set the FormBorderStyle to none and WindowState to Maximized . Applications should be displayed on one monitor so I would not try to put the IDE on both .
    Coding4fun Be a good forum member mark posts that contain the answers to your questions or those that are helpful
    Please format the code in your posts with the button . Makes it easier to read .
    viernes, 15 de enero de 2010 6:04
  • Ok, I have made a frmVideo and placed AxWindowsMediaPlayer2 in it

    I have the button press opening frmVideo.show and the video plays.

    How do I close the video/form when complete?  Via a timer?

    I still can not figure out how to drag to the second monitor in the IDE.


    viernes, 15 de enero de 2010 6:16
  • A video card that has dual monitor support usually come with a utility that allows you to configure it to use two monitors and sometimes where the second monitor should be in relation to the primary monitor . Usually you would set it to be to the left or right . I assume you have the second display enabled . try dragging the IDE off of the sides of your display and see if it goes to the second display . Try all sides . For the MediaPlayer try this first form1 the form to choose a video

    Public Class Form1

        
    Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
            
    Dim ofd As New OpenFileDialog
            ofd.Filter = 
    "Video files (*.wmv)|*.wmv"
            ofd.InitialDirectory = My.Computer.FileSystem.SpecialDirectories.Desktop
            
    If ofd.ShowDialog = Windows.Forms.DialogResult.OK Then
                Dim PlayForm As New MediaPlayerForm
                PlayForm.Show()
                PlayForm.PlayMedia(ofd.FileName)
            
    End If
        End Sub

    End
     Class

    Next a form to play the video I'll call it MediaPlayerForm as you see in the above code


    Public Class MediaPlayerForm

        
    Public Sub PlayMedia(ByVal Video As String)

            AxWindowsMediaPlayer1.URL = Video
            AxWindowsMediaPlayer1.Ctlcontrols.play()

        
    End Sub

        Private Sub AxWindowsMediaPlayer1_PlayStateChange _
        (
    ByVal sender As System.Object, _
         
    ByVal e As AxWMPLib._WMPOCXEvents_PlayStateChangeEvent) _
         
    Handles AxWindowsMediaPlayer1.PlayStateChange

            
    If AxWindowsMediaPlayer1.playState = WMPLib.WMPPlayState.wmppsPlaying Then
                AxWindowsMediaPlayer1.fullScreen = True
            Else
                If AxWindowsMediaPlayer1.fullScreen = True Then
                    AxWindowsMediaPlayer1.fullScreen = False
                End If
            End If

            If AxWindowsMediaPlayer1.playState = _
            WMPLib.WMPPlayState.wmppsStopped _
            
    Or _
            AxWindowsMediaPlayer1.playState = _
            WMPLib.WMPPlayState.wmppsMediaEnded 
    Then

                Me.Close()

            
    End If

        End Sub
    End
     Class


    ( you will have to add your code to put it on the second display)

    Coding4fun Be a good forum member mark posts that contain the answers to your questions or those that are helpful
    Please format the code in your posts with the button . Makes it easier to read .
    • Editado bdbodger viernes, 15 de enero de 2010 8:58
    viernes, 15 de enero de 2010 6:53
  • Hi

    Well this Gateway laptop has the Mitsubishi projector plugged into the back.  Using Vista, i have the projector using Screen 2, set to expand my desktop.

    I've used multiple monitor setups before.  I have never tried it with an IDE like VB 2008.

    If I run it in maximize, it just fills one window or the other, should I drag it over.

    I'm stumped.

    Also, how to close wmp after the video plays?

    viernes, 15 de enero de 2010 7:06
  • My code already closes it when the video stops . Why have the IDE on a projector ? You can try and drag one side of the IDE and stretch it  over 2 monitors but I don't think that will be any good . Why do you want to do that so bad ?
    Coding4fun Be a good forum member mark posts that contain the answers to your questions or those that are helpful
    Please format the code in your posts with the button . Makes it easier to read .
    viernes, 15 de enero de 2010 7:17
  • I just do not now how to make the IDE work across multiple monitors.

    You see, if the answer to this problem is to simply drag a form to screen 1 (display1, right?) then you can understand why I am stumped :-)

    This program is what I use to generate sounds for my full sized R2-D2.  (http://paulsr2d2.blogspot.com)

    The code sample found, I have tweaked a great deal, so that a Windows xbox controller can play a random sound from a specific folder. 

    I was able to obtain a mini LED projector and the netbook inside of R2 sees it as a second monitor.

    The goal is so that when a button is pressed for video, the video will play on screen2 (display1), prompting the projector to play the video as R2-D2 did in the movie.

    However when the video plays, the main form looses focus, so the "stop" playback does not work (which I can live with).

    Also, while the video plays in the main screen for now, it does not close, so the program is hung until you intervene with an alt-f4

    So if this entire series of questions seemed eccentric, now you know what I am trying to do  :-)

    viernes, 15 de enero de 2010 16:00
  • Well I didnt need the first snippet to specify the path...tell you what, here's a cut/paste of my frmVideo...

    Public Class frmVideo
    
        Private Sub AxWindowsMediaPlayer2_Enter(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles AxWindowsMediaPlayer2.Enter
    
    
            AxWindowsMediaPlayer2.URL = "D:\r2d2\7\leiaHires2.wmv"
    
            If AxWindowsMediaPlayer2.playState = WMPLib.WMPPlayState.wmppsPlaying Then
                AxWindowsMediaPlayer2.fullScreen = True
            Else
                If AxWindowsMediaPlayer2.fullScreen = True Then
                    AxWindowsMediaPlayer2.fullScreen = False
                End If
            End If
    
            If AxWindowsMediaPlayer2.playState = _
            WMPLib.WMPPlayState.wmppsStopped _
            Or _
            AxWindowsMediaPlayer2.playState = _
            WMPLib.WMPPlayState.wmppsMediaEnded Then
    
                Me.Close()
    
            End If
    
    
    
    
        End Sub
    End Class
    Now upon pressing the button, the Princess Leia clip plays but does not close the Windows Media Player window/form.

    We're getting closer!
    sábado, 16 de enero de 2010 5:05
  • That does not work because of the event you have it in .  The Enter event is triggered when the mouse enters the control . Click on the media player in the IDE . In the property grid click the lightning bolt icon to change the property grid to a list of events that the control can handle . I used the PlayStateChange event which is triggered by the media control when the playstate changes .
    Coding4fun Be a good forum member mark posts that contain the answers to your questions or those that are helpful
    Please format the code in your posts with the button . Makes it easier to read .
    sábado, 16 de enero de 2010 5:37
  • Ok, I found the PlayStateChange, what should I enter into that?
    sábado, 16 de enero de 2010 5:51
  • The code from your last post . Double click the space beside the event to have the IDE create the sub for you .
    Coding4fun Be a good forum member mark posts that contain the answers to your questions or those that are helpful
    Please format the code in your posts with the button . Makes it easier to read .
    sábado, 16 de enero de 2010 5:52
  • Oh nevermind!  I double clicked in the field to the right and it brought up the code

    THAT WORKED!

    Excellent!!

    Now....drum roll....how do we get that into the second display?
    sábado, 16 de enero de 2010 5:54
  • You might give this a try


        
    Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
            
    For Each S As Screen In Screen.AllScreens
                
    If Not S.Equals(Screen.PrimaryScreen) Then
                    Me.Location = New Point(S.Bounds.X, 0)
                
    End If
            Next
        End Sub

    Coding4fun Be a good forum member mark posts that contain the answers to your questions or those that are helpful
    Please format the code in your posts with the button . Makes it easier to read .

    I added this to the form load for frmVideo and its not going to the other monitor.  Hmmm   Still digging!
    sábado, 16 de enero de 2010 17:19
  • Let me show you what frmVideo looks like, so you have a clean template....I have searched MSDN and Bing for some code snippets that are supposed to size and display on the secondary monitor.  This seems to be a problematic question but I also wonder if I am activating the videoplayback before the application has sized out and found the second monitor?

    Public Class frmVideo
    
        Private Sub AxWindowsMediaPlayer2_Enter(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles AxWindowsMediaPlayer2.Enter
    
            AxWindowsMediaPlayer2.URL = "D:\r2d2\7\leiaHires2.wmv"
    
            
    
    
    
        End Sub
    
        Private Sub AxWindowsMediaPlayer2_PlayStateChange(ByVal sender As System.Object, ByVal e As AxWMPLib._WMPOCXEvents_PlayStateChangeEvent) Handles AxWindowsMediaPlayer2.PlayStateChange
            If AxWindowsMediaPlayer2.playState = WMPLib.WMPPlayState.wmppsPlaying Then
                AxWindowsMediaPlayer2.fullScreen = True
            Else
                If AxWindowsMediaPlayer2.fullScreen = True Then
                    AxWindowsMediaPlayer2.fullScreen = False
                End If
            End If
    
            If AxWindowsMediaPlayer2.playState = _
            WMPLib.WMPPlayState.wmppsStopped _
            Or _
            AxWindowsMediaPlayer2.playState = _
            WMPLib.WMPPlayState.wmppsMediaEnded Then
    
                Me.Close()
    
            End If
    
        End Sub
    
        Private Sub frmVideo_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
            'Dim s As Screen
            'For Each s In Screen.AllScreens
            '    If Not s.Primary Then Exit For
            'Next
            'Me.Bounds = s.Bounds
            'Me.WindowState = FormWindowState.Maximized
    
            Dim screens() As Screen = Screen.AllScreens
    
            ' Get the current screen and its location in the list of screens
            Dim currentScreen As Screen = Screen.FromControl(Me)
            Dim currentScreenIndex As Integer = Array.IndexOf(screens, currentScreen)
    
            ' Get the index of the next screen
            Dim nextScreenIndex As Integer = currentScreenIndex + 1
            If nextScreenIndex = screens.Length Then
                nextScreenIndex = 0
            End If
    
            ' Get the location of the window relative to the top-left corner of the current screen
            Dim locationInScreenCoordinates As New Point()
            locationInScreenCoordinates.X = Location.X - currentScreen.Bounds.X
            locationInScreenCoordinates.Y = Location.Y - currentScreen.Bounds.Y
    
            ' Get the location of an equivalent point on the next screen
            Dim nextScreen As Screen = screens(nextScreenIndex)
            Dim newLocation As New Point()
            newLocation.X = nextScreen.Bounds.X + locationInScreenCoordinates.X
            newLocation.Y = nextScreen.Bounds.Y + locationInScreenCoordinates.Y
    
            ' If the window falls outside the bounds of the next screen, move the window so that it
            ' falls within the bounds of the screen.
            If Not nextScreen.Bounds.Contains(newLocation) Then
                If nextScreen.Bounds.Right < newLocation.X Then
                    newLocation.X = nextScreen.Bounds.Right - Width
                ElseIf newLocation.X < nextScreen.Bounds.Left Then
                    newLocation.X = nextScreen.Bounds.Left
                End If
    
                If newLocation.Y < nextScreen.Bounds.Top Then
                    newLocation.Y = nextScreen.Bounds.Top
                ElseIf nextScreen.Bounds.Bottom < newLocation.Y Then
                    newLocation.Y = nextScreen.Bounds.Bottom - Height
                End If
            End If
    
            ' If the window is larger than the screen, make it fit.
            If Width > nextScreen.Bounds.Width Then
                Width = nextScreen.Bounds.Width
            End If
    
            If Height > nextScreen.Bounds.Height Then
                Height = nextScreen.Bounds.Height
            End If
    
            ' Place the window
            Me.Location = newLocation
    
    
    
        End Sub
    End Class
    sábado, 16 de enero de 2010 18:27
  • This is something you will have to do on your own I do not have a dual setup at the moment . When you right click on the desktop and choose properties and on the dialog that opens on the settings tab do you have the second display enabled ?
    Coding4fun Be a good forum member mark posts that contain the answers to your questions or those that are helpful
    Please format the code in your posts with the button . Makes it easier to read .
    sábado, 16 de enero de 2010 18:43
  • Yes, there is a second display showing.

    When I do the test numbers, the projector one comes up as two.

    sábado, 16 de enero de 2010 18:59
  • You know what's interesting, I found a code snippet elsewhere that DID put a form on the other monitor...

    All you need to do to show a form on a specifi screen is to set its Location property so it is in the specified screen Bounds:
    
    Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
    
    Dim form As New Form
    
    Dim screen As Screen
    
    ' We want to display a form on screen 1
    
    screen = screen.AllScreens(1)
    
    ' Set the StartPosition to Manual otherwise the system will assign an automatic start position
    
    form.StartPosition = FormStartPosition.Manual
    
    ' Set the form location so it appears at Location (100, 100) on the screen 1
    
    form.Location = screen.Bounds.Location + new Point(100, 100)
    
    ' Show the form
    
    form.ShowDialog(Me)
    
    End Sub
    
    

    What I am trying to determine is how to modify how I initiate frmVideo to load.  Currently I used this in the main form...

    If IsButtonPressed(buttonStates(7)) Then
    
                ArtooSoundz.frmVideo.Show()
    
                'PlayRandomFile("7")
                'button 7 is intended for the Princess Leia video on screen 2
    
            End If
    I am curious if I need to change how we call up the frmVideo from the button press instead of trying to alter how frmVideo loads?

    Soooo close!

    sábado, 16 de enero de 2010 20:21
  • You might give this a try


        
    Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
            
    For Each S As Screen In Screen.AllScreens
                
    If Not S.Equals(Screen.PrimaryScreen) Then
                    Me.Location = New Point(S.Bounds.X, 0)
                
    End If
            Next
        End Sub

    Coding4fun Be a good forum member mark posts that contain the answers to your questions or those that are helpful
    Please format the code in your posts with the button . Makes it easier to read .

    Did you try this code? That code you just posted for the button click is strange code why don't you doubleclick on the button and have the IDE create the handler for the button click . You can set properties on the video form before you show it . you can create a new instance of the video form set the properties then show it .


        
    Private Sub Button1_Click _
        (
    ByVal sender As System.Object, _
         
    ByVal e As System.EventArgs) Handles Button1.Click

            
    Dim NewForm As New frmVideo
            NewForm.StartPosition = FormStartPosition.Manual
            NewForm.WindowState = FormWindowState.Maximized
            NewForm.Location = _
            
    New Point(Screen.AllScreens(0).Bounds.X, Screen.AllScreens(0).Bounds.Y)

            NewForm.AxWindowsMediaPlayer1.URL = 
    My.Computer.FileSystem.SpecialDirectories.Desktop & "\Mystery.wmv"
            NewForm.Show()
            NewForm.AxWindowsMediaPlayer1.Ctlcontrols.play()

        
    End Sub

    Coding4fun Be a good forum member mark posts that contain the answers to your questions or those that are helpful
    Please format the code in your posts with the button . Makes it easier to read .
    sábado, 16 de enero de 2010 20:42
  • So would I remove the frmVideo completely and have this launch from the main form?
    sábado, 16 de enero de 2010 20:53
  • Ok, I removed the frmVideo but get any error... frmVideo not defined
    sábado, 16 de enero de 2010 20:58

  • No!!
    that code creates a copy of the frmVideo and shows it . It can't do that if frmVideo does not exist. I am just trying to show you how you can create an instance of frmVideo and run it from your main form . If you show frmVideo then close it you may have a problem if you try to show it again when it is closed it may be disposed of and you will get an error . Also later you may want to run more than one video with this method you can create a new instance of the form and set what video to play instead of setting it on frmVideo .
    Coding4fun Be a good forum member mark posts that contain the answers to your questions or those that are helpful
    Please format the code in your posts with the button . Makes it easier to read .
    sábado, 16 de enero de 2010 20:59
  • I take it that your very new to VB programming .
    Coding4fun Be a good forum member mark posts that contain the answers to your questions or those that are helpful
    Please format the code in your posts with the button . Makes it easier to read .
    sábado, 16 de enero de 2010 21:10
  • ____.

    And I didnt save the change but VB 2008 aint seeing my previous saved. 
    sábado, 16 de enero de 2010 21:13
  • Ok, got it back....what is "mystery.wmv" ?
    sábado, 16 de enero de 2010 21:16
  • Doh!!  that is an example from my system . Use the path to your video . Is it really that hard to figure out ?
    Coding4fun Be a good forum member mark posts that contain the answers to your questions or those that are helpful
    Please format the code in your posts with the button . Makes it easier to read .
    sábado, 16 de enero de 2010 21:23
  • Ok, here is what I have in the portion in the main form ...

    PlayRandomFile("7")
                'button 7 is intended for the Princess Leia video on screen 2
    
                Dim NewForm As New frmVideo
                NewForm.StartPosition = FormStartPosition.Manual
                NewForm.WindowState = FormWindowState.Maximized
                NewForm.Location = _
                New Point(Screen.AllScreens(0).Bounds.X, Screen.AllScreens(0).Bounds.Y)
    
                NewForm.AxWindowsMediaPlayer2.URL = My.Computer.FileSystem.SpecialDirectories.Desktop & "D:\r2d2\7\leiaHires2.wmv"
                NewForm.Show()
                NewForm.AxWindowsMediaPlayer2.Ctlcontrols.play()
    
    
            End If
    Question:  Do I simply want to use one AxWindowsMediaPlayer ( 1 ) ?

    frmVideo has AXWindowsMediaPlayer2 on it, so I changed what you gave me to that

    If I try using this, all I get is an empty form with no video play.

    If I rem it out and use just...

    If IsButtonPressed(buttonStates(7)) Then
    
                ArtooSoundz.frmVideo.Show()
    ...then I get video....in the primary console.

    Here's what frmVideo looks like now....I think its completely screwed up and I dont get my vb overwrites saved copies without selecting to do so...sigh


    Public Class frmVideo
    
        Private Sub AxWindowsMediaPlayer2_Enter(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles AxWindowsMediaPlayer2.Enter
    
            AxWindowsMediaPlayer2.URL = "D:\r2d2\7\leiaHires2.wmv"
    
    
    
    
    
        End Sub
    
        Private Sub AxWindowsMediaPlayer2_PlayStateChange(ByVal sender As System.Object, ByVal e As AxWMPLib._WMPOCXEvents_PlayStateChangeEvent) Handles AxWindowsMediaPlayer2.PlayStateChange
    
            If AxWindowsMediaPlayer2.playState = WMPLib.WMPPlayState.wmppsPlaying Then
                AxWindowsMediaPlayer2.fullScreen = True
            Else
                If AxWindowsMediaPlayer2.fullScreen = True Then
                    AxWindowsMediaPlayer2.fullScreen = False
                End If
            End If
    
            If AxWindowsMediaPlayer2.playState = _
            WMPLib.WMPPlayState.wmppsStopped _
            Or _
            AxWindowsMediaPlayer2.playState = _
            WMPLib.WMPPlayState.wmppsMediaEnded Then
    
                Me.Close()
    
            End If
    
        End Sub
    
        Private Sub frmVideo_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
            ''Dim s As Screen
            ''For Each s In Screen.AllScreens
            ''    If Not s.Primary Then Exit For
            ''Next
            ''Me.Bounds = s.Bounds
            ''Me.WindowState = FormWindowState.Maximized
    
            'Dim screens() As Screen = Screen.AllScreens
    
            '' Get the current screen and its location in the list of screens
            'Dim currentScreen As Screen = Screen.FromControl(Me)
            'Dim currentScreenIndex As Integer = Array.IndexOf(screens, currentScreen)
    
            '' Get the index of the next screen
            'Dim nextScreenIndex As Integer = currentScreenIndex + 1
            'If nextScreenIndex = screens.Length Then
            '    nextScreenIndex = 0
            'End If
    
            '' Get the location of the window relative to the top-left corner of the current screen
            'Dim locationInScreenCoordinates As New Point()
            'locationInScreenCoordinates.X = Location.X - currentScreen.Bounds.X
            'locationInScreenCoordinates.Y = Location.Y - currentScreen.Bounds.Y
    
            '' Get the location of an equivalent point on the next screen
            'Dim nextScreen As Screen = screens(nextScreenIndex)
            'Dim newLocation As New Point()
            'newLocation.X = nextScreen.Bounds.X + locationInScreenCoordinates.X
            'newLocation.Y = nextScreen.Bounds.Y + locationInScreenCoordinates.Y
    
            '' If the window falls outside the bounds of the next screen, move the window so that it
            '' falls within the bounds of the screen.
            'If Not nextScreen.Bounds.Contains(newLocation) Then
            '    If nextScreen.Bounds.Right < newLocation.X Then
            '        newLocation.X = nextScreen.Bounds.Right - Width
            '    ElseIf newLocation.X < nextScreen.Bounds.Left Then
            '        newLocation.X = nextScreen.Bounds.Left
            '    End If
    
            '    If newLocation.Y < nextScreen.Bounds.Top Then
            '        newLocation.Y = nextScreen.Bounds.Top
            '    ElseIf nextScreen.Bounds.Bottom < newLocation.Y Then
            '        newLocation.Y = nextScreen.Bounds.Bottom - Height
            '    End If
            'End If
    
            '' If the window is larger than the screen, make it fit.
            'If Width > nextScreen.Bounds.Width Then
            '    Width = nextScreen.Bounds.Width
            'End If
    
            'If Height > nextScreen.Bounds.Height Then
            '    Height = nextScreen.Bounds.Height
            'End If
    
            '' Place the window
            'Me.Location = newLocation
    
    
    
        End Sub
    End Class
    As you can see, I have a good deal rem'd out as I try to hunt this down.

    I think I have frmVideo and WMP 2 restored to the settings it had before (fullsize, url = , etc)


    sábado, 16 de enero de 2010 21:58
  • I take it that your very new to VB programming .
    Coding4fun Be a good forum member mark posts that contain the answers to your questions or those that are helpful
    Please format the code in your posts with the button . Makes it easier to read .

    Yeah....as I said earlier, a noob.

    I was pretty good with VB6 but .Net is taking me a bit to grasp
    sábado, 16 de enero de 2010 21:59
  • Come on does this look right to you

            NewForm.AxWindowsMediaPlayer2.URL = My.Computer.FileSystem.SpecialDirectories.Desktop & "D:\r2d2\7\leiaHires2.wmv"

    Don't you think that if the video is not on the desktop that will not work . Your going to have to learn how to specify a path if your going to know how to program . Try this instead .

      NewForm.AxWindowsMediaPlayer2.URL = "D:\r2d2\7\leiaHires2.wmv"


    My.Computer.FileSystem.SpecialDirectories.Desktop can be used to point to your desktop directory when pointing to a file that is on the desktop . If your going to set what video to play from the main form then remove this from frmVideo . I though we decidede not to use the enter event handler !!

     Private Sub AxWindowsMediaPlayer2_Enter(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles AxWindowsMediaPlayer2.Enter

            AxWindowsMediaPlayer2.URL = 
    "D:\r2d2\7\leiaHires2.wmv"

        End Sub

    I think you need to reread all the posts in this thread and do some trial and error . Copy and paste programming never works .

    Coding4fun Be a good forum member mark posts that contain the answers to your questions or those that are helpful
    Please format the code in your posts with the button . Makes it easier to read .
    sábado, 16 de enero de 2010 22:09
  • Come on does this look right to you

            NewForm.AxWindowsMediaPlayer2.URL = My.Computer.FileSystem.SpecialDirectories.Desktop & "D:\r2d2\7\leiaHires2.wmv"


    I was just asking...as you can see in my prior posts, I had found the proper nomenclature correct with .URL 

    Look, as I have said along the way, I'm trying to learn as I go so this robot project can continue to make kids at the hospital smile.  I apologize if I am learning out of sequence or insulting your time and knowlegde asking such things.  Someone helped you out way back when.  I appreciate you taking the time to assist.

    You are giving some good bits and snippets of code and I have been doing my best to learn them.

    I'm trying to do more than cut and paste but learn as ask how and where these functions should be placed.

    sábado, 16 de enero de 2010 22:21
  • Excuse my tough love but you have everything you need to know but I'll review it for for

    Main form:

    create a sub to start the video by creating a new instance of frmVideo


        
    Private Sub Button1_Click _
        (
    ByVal sender As System.Object, _
         
    ByVal e As System.EventArgs) Handles Button1.Click

            
    Dim NewForm As New frmVideo
            NewForm.StartPosition = FormStartPosition.Manual
            NewForm.WindowState = FormWindowState.Maximized
            NewForm.Location = _
            
    New Point(Screen.AllScreens(1).Bounds.X, Screen.AllScreens(1).Bounds.Y)

            NewForm.AxWindowsMediaPlayer1.URL = 
    "D:\r2d2\7\leiaHires2.wmv"
            NewForm.Show()
            NewForm.AxWindowsMediaPlayer1.Ctlcontrols.play()

        
    End Sub


    frmVideo:

    Public Class frmVideo

        
    Private Sub AxWindowsMediaPlayer2_PlayStateChange(ByVal sender As System.Object, ByVal e As AxWMPLib._WMPOCXEvents_PlayStateChangeEvent) Handles AxWindowsMediaPlayer2.PlayStateChange

            
    If AxWindowsMediaPlayer2.playState = WMPLib.WMPPlayState.wmppsPlaying Then
                AxWindowsMediaPlayer2.fullScreen = True
            Else
                If AxWindowsMediaPlayer2.fullScreen = True Then
                    AxWindowsMediaPlayer2.fullScreen = False
                End If
            End If

            If AxWindowsMediaPlayer2.playState = _
            WMPLib.WMPPlayState.wmppsStopped _
            
    Or _
            AxWindowsMediaPlayer2.playState = _
            WMPLib.WMPPlayState.wmppsMediaEnded 
    Then

                Me.Close()

            
    End If

        End Sub

    End
     Class

    Coding4fun Be a good forum member mark posts that contain the answers to your questions or those that are helpful
    Please format the code in your posts with the button . Makes it easier to read .
    sábado, 16 de enero de 2010 22:30
  • I understand tough love....

    I have the frmVideo looking just as your example did.

    The only difference from what have in the mainfrm is it is not a mouse click event.

    So I am back to where we were   :-)

    Now I am reviewing your posts and trying to determine why this isn't going to screen 2.

    I have played with the sample file I have posted but not luck yet.

    I'll give it a break for a bit as I have to re-wire R2's head for some changes to the lighting in the LEDs.  Newer, smaller batteries arrived last week that knock 7 pounds of weight of the droid.

    sábado, 16 de enero de 2010 22:43
  • Ok if you have it working that's good you just have to get it to show on the second display . Good luck
    Coding4fun Be a good forum member mark posts that contain the answers to your questions or those that are helpful
    Please format the code in your posts with the button . Makes it easier to read .
    sábado, 16 de enero de 2010 22:56
  • That's the hard part.

    See what stumps me is this code snippet sees and goes right on over to the second display fine...

    Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
    
    Dim form As New Form
    
    Dim screen As Screen
    
    ' We want to display a form on screen 1
    
    screen = screen.AllScreens(1)
    
    ' Set the StartPosition to Manual otherwise the system will assign an automatic start position
    
    form.StartPosition = FormStartPosition.Manual
    
    ' Set the form location so it appears at Location (100, 100) on the screen 1
    
    form.Location = screen.Bounds.Location + new Point(100, 100)
    
    ' Show the form
    
    form.ShowDialog(Me)
    
    End Sub
    
    

    The code you provided....

    Dim NewForm As New frmVideo
                NewForm.StartPosition = FormStartPosition.Manual
                NewForm.WindowState = FormWindowState.Maximized
                NewForm.Location = _
                New Point(Screen.AllScreens(1).Bounds.X, Screen.AllScreens(1).Bounds.Y)
    
                NewForm.AxWindowsMediaPlayer2.URL = "D:\r2d2\7\leiaHires2.wmv"
                NewForm.Show()
                NewForm.AxWindowsMediaPlayer2.Ctlcontrols.play()
    I'm curious about the last 3 lines...

    1)  WMP opens the video but we havent specified where
    2)  The new form shows
    3)  WMP is tasked to play

    Ideas?

    sábado, 16 de enero de 2010 23:44
  • Upon playing with the code snip more, its interesting...yes, that snippet will place a second form on the second monitor.

    I put a picture on the form2 I wanted to be generated and....the form, with picturebox, opened!

    I replaced the picturebox with a Windows Media Player control and it no longer works.

    Ponder...ponder...ponder....
    domingo, 17 de enero de 2010 0:30
  • If your frmVideo has a windows media player on it and the name of it is AxWindowsMediaPlayer2 then the 3rd last line sets what video to play . The 2nd to last line shows the copy of frmVideo that I called NewForm in the Dim statement above that on the first line . The last line tells the media player to play the video . Simple . In the code snippet it uses Screen.AllScreens(1) as you can tell they are referencing one screen in a collection by it's index number in that case the second screen if the collection is 0 based .

    Public Shared ReadOnly Property AllScreens() As System.Windows.Forms.Screen()
         Member of 
    System.Windows.Forms.Screen

    Summary:
    Gets an array of all displays on the system.

    Return Values:
    An array of type System.Windows.Forms.Screen, containing all displays on the system.

    As you see it is a 0 based array of the screens on your system so Screen.AllScreens(1) is the second display . The NewForm.Location line puts the new frmVideo on the second display . The Location property of a form is the top left corner of the form in screen coordinates .

    Coding4fun Be a good forum member mark posts that contain the answers to your questions or those that are helpful
    Please format the code in your posts with the button . Makes it easier to read .
    domingo, 17 de enero de 2010 3:12

  •    
        
    Private Sub Button1_Click _
        (
    ByVal sender As System.Object, _
         
    ByVal e As System.EventArgs) Handles Button1.Click

            
    ' Create a copy of frmVideo
            Dim NewForm As New frmVideo

            
    'Set the start Position of the new form to Manual
            NewForm.StartPosition = FormStartPosition.Manual

            
    'Set the Window to start Maximized
            NewForm.WindowState = FormWindowState.Maximized

            
    'Set the Screen coordinates of the new form using
            'the bounds of the Second Display ( bounds being the boundry or rectangle it uses )
            NewForm.Location = _
            
    New Point(Screen.AllScreens(1).Bounds.X, Screen.AllScreens(1).Bounds.Y)

            
    'Set what video to play on the copy of frmVideo
            NewForm.AxWindowsMediaPlayer2.URL = "D:\r2d2\7\leiaHires2.wmv"

            'Show the new form we created from frmVideo
            NewForm.Show()

            
    'Tell the WindowsMediaPlayer control on the form to play the video
            NewForm.AxWindowsMediaPlayer2.Ctlcontrols.play()

        
    End Sub

    Coding4fun Be a good forum member mark posts that contain the answers to your questions or those that are helpful
    Please format the code in your posts with the button . Makes it easier to read .
    domingo, 17 de enero de 2010 3:20
  • I have a multi-monitor setup (laptop with external projector).  It shows as Display 2.

    I hae found code snippets and examples of how to get a form to display on the second display.  I have had the samples create a new form with a picture box successfully on the second monitor.

    However, getting this to work with Windows Media Player has me stumped.

    I have no been able to find anything in the WMP documentation that shows how to select the monitor.

    Any tips?

    I'm a newbie...hobby programmer, if that!  So, please be patient with me....thanks!

    • Combinado Jeff Shan viernes, 22 de enero de 2010 8:19 Merge it to keep the same topic in one thread
    domingo, 17 de enero de 2010 3:23
  • Do you think double posting is going to change anything ?

    http://social.msdn.microsoft.com/Forums/en-US/vbgeneral/thread/1847c2f7-8ef5-4af9-a4b2-a190f344673e
    Coding4fun Be a good forum member mark posts that contain the answers to your questions or those that are helpful
    Please format the code in your posts with the button . Makes it easier to read .
    domingo, 17 de enero de 2010 3:31
  • Well you didn't seem to have the answer then, or now.

    I don't recall requiring your approval to ask a question
    domingo, 17 de enero de 2010 3:42
  • The code I gave you works I have tested it . Double posting is bad forum etiquette you can hear it from me or another member . It's not my fault you can't understand it .
    Coding4fun Be a good forum member mark posts that contain the answers to your questions or those that are helpful
    Please format the code in your posts with the button . Makes it easier to read .
    domingo, 17 de enero de 2010 3:45
  • What you posted doesnt work

    If you had a dual monitor setup, you would see that too.

    domingo, 17 de enero de 2010 3:54
  • Thank you for the enhanced remarks.

    I'll try it out again
    domingo, 17 de enero de 2010 4:09
  • Remove this line

      'Set the Window to start Maximized
            NewForm.WindowState = FormWindowState.Maximized

    I just tested it on a dual monitor setup and it works if you remove that line .

    My setup


    Coding4fun Be a good forum member mark posts that contain the answers to your questions or those that are helpful
    Please format the code in your posts with the button . Makes it easier to read .
    domingo, 17 de enero de 2010 4:37
  • I find this line is not needed the video plays when you set the url


            'Tell the WindowsMediaPlayer control on the form to play the video
            NewForm.AxWindowsMediaPlayer2.Ctlcontrols.play()

    New Code :

        
    Private Sub Button1_Click _
        (
    ByVal sender As System.Object, _
         
    ByVal e As System.EventArgs) Handles Button1.Click

            
    ' Create a copy of frmVideo
            Dim NewForm As New frmVideo

            
    'Set the start Position of the new form to Manual
            NewForm.StartPosition = FormStartPosition.Manual

            
    'Set the Screen coordinates of the new form using
            'the bounds of the Second Display ( bounds being the boundry or rectangle it uses )
            NewForm.Location = _
            
    New Point(Screen.AllScreens(1).Bounds.X, Screen.AllScreens(1).Bounds.Y)

            
    'Set what video to play on the copy of frmVideo
            NewForm.AxWindowsMediaPlayer2.URL = "D:\r2d2\7\leiaHires2.wmv"

            'Show the new form we created from frmVideo
            NewForm.Show()

        
    End Sub

    New Code for frmVideo :

    Public Class frmVideo
        
    Private Sub AxWindowsMediaPlayer2_PlayStateChange(ByVal sender As System.Object, ByVal e As AxWMPLib._WMPOCXEvents_PlayStateChangeEvent) Handles AxWindowsMediaPlayer2.PlayStateChange

            
    If AxWindowsMediaPlayer2.playState = WMPLib.WMPPlayState.wmppsPlaying Then
                AxWindowsMediaPlayer2.fullScreen = True
            End If

            If AxWindowsMediaPlayer2.playState = _
            WMPLib.WMPPlayState.wmppsStopped _
            
    Or _
            AxWindowsMediaPlayer2.playState = _
            WMPLib.WMPPlayState.wmppsMediaEnded 
    Then

                Me.Close()

            
    End If

        End Sub

    End
     Class


    Coding4fun Be a good forum member mark posts that contain the answers to your questions or those that are helpful
    Please format the code in your posts with the button . Makes it easier to read .
    domingo, 17 de enero de 2010 4:54
  • I suspect it would be be your mistake because BD is rarely wrong.

    Renee
    domingo, 17 de enero de 2010 4:59
  • Ok, still the same result for me

    Just to verify the multi-monitor setup, I replaced the projector with a 17" monitor.

    Would you like the full source to try duplicating?
    domingo, 17 de enero de 2010 5:10
  • Thanks Renee . If you look at the other thread you will see that I setup a dual display with my netbook and a 7" touchscreen I had just to prove to myself that it really does work and with a slight modification of the code , just not maximizing the form the video plays on , I have it working just fine .
    Coding4fun Be a good forum member mark posts that contain the answers to your questions or those that are helpful
    Please format the code in your posts with the button . Makes it easier to read .
    domingo, 17 de enero de 2010 5:10
  • We're sorting it out....as the other thread shows.

    Getting closer!
    domingo, 17 de enero de 2010 5:12
  • Start a new project and use just the last code I posted . On the first form put a button and the button code I posted . Add a new form call it frmVideo , add a windows media player control to it and name it AxWindowsMediaPlayer2 , set the dock property of the media player control to fill and use the second bit of code I posted . If that works then maybe there is something else stopping it from working . Like I said on my setup with my Netbook and a 7" touchscreen I used that code and it works good .
    Coding4fun Be a good forum member mark posts that contain the answers to your questions or those that are helpful
    Please format the code in your posts with the button . Makes it easier to read .
    domingo, 17 de enero de 2010 5:15
  • Hmmm, well isn't that interesting.

    Well I wonder what the heck is blocking it from going over.

    Thanks for checking it out....I'm going to scan through the frmVideo for anything odd looking.

    domingo, 17 de enero de 2010 5:26
  • SOLVED!

    I compared the frmVideo settings side by side with the sample you made.

    Once I set the WindowsState to Normal in the frmVideo setting, it started to work!

    More in a bit...I want to verify all is well on the test laptop, then try it on R2's netbook.
    domingo, 17 de enero de 2010 5:41


  •  


    Coding4fun Be a good forum member mark posts that contain the answers to your questions or those that are helpful
    Please format the code in your posts with the button . Makes it easier to read .
    domingo, 17 de enero de 2010 5:50
  • I am soooo pleased this works!

    Now I need to fabricate a mounting that will fit inside R2's head.

    I am in the process of uploading a video of what you helped make to youtube now   :-)
    domingo, 17 de enero de 2010 6:43
  • Nice video the only other thing I might suggest you try is to set the FormBorderStyle to none on frmVideo , I noticed that when the form loaded on the projector that the form showed the windows border . Then on the mediaplayer control set the uimode to none the default is full that will stop the controls from showing .
    Coding4fun Be a good forum member mark posts that contain the answers to your questions or those that are helpful
    Please format the code in your posts with the button . Makes it easier to read .
    domingo, 17 de enero de 2010 7:20
  • Excellent idea

    Isn't it nice to see your help payoff in a most interesting way??  LOL
    domingo, 17 de enero de 2010 7:29




  • Coding4fun Be a good forum member mark posts that contain the answers to your questions or those that are helpful
    Please format the code in your posts with the button . Makes it easier to read .
    domingo, 17 de enero de 2010 7:32
  • One thing I noticed once installing the application on the netbook...the netbook needed the latest and great WMP 11.  It had 9 and at the end of the video clip, it would close the entire application.   Easy enough fix!

    I took a day off from the program to do some more work on R2.

    I have another friend who is finishing up the 'death star plans' video clip.  The scene in the original star wars movie before the big battle, where they get the 3D death star read out to see their target.  Very cool!

    Now, if I wanted the application to open a random file with a "*.wmv", just put the wildcard in the path?

    I'm also working to tweak that no-name brand netbook as I am seeing a delay between button press to play.  Makes sense, WMP is a heavier hitter than Audo.Play was. 

    That netbook only came with a 2gb solid state hard disk, so it has no swap file....it only has 450mb free.  Looks like a new netbook is on the short "to do " list.

    Again, my many thanks!  I've learned a lot and subscribe to LearnVisualStudio.com  I need to keep taking the tutorials and keep learning!

    Paul
    lunes, 18 de enero de 2010 3:11