Need help displaying videos

Just starting out? Need help? Post your questions and find answers here.
ron2
New User
New User
Posts: 6
Joined: Mon Nov 05, 2012 6:56 am

Need help displaying videos

Post by ron2 »

I'm writing a program to help people learn sign language. It requires me to load short (<5 secs) clips demonstrating each sign. My program is able to load the video and play it. But I am running into 2 problems.

- the video only plays in the upper left of the window - i need it to play on
the right side of the screen a little lower down
- the movie plays behind the stringgadgets on the left side of the window until
i move the window

Code: Select all

Procedure p_PlayPracticeVideo()
      If InitMovie() = 450
        MessageRequester("Error", "Can't initialize movie playback !", 0) 
        End
      Else
        If LoadMovie(450, "Videos\ASL.wmv")
          InitSprite()
          OpenWindowedScreen(WindowID(0), 780, 35, 200, 244, 0, 0, 0)
          PlayMovie(450, WindowID(0))
        Else
          MessageRequester("Error", "Can't load the movie...", 0)
        EndIf
      EndIf
EndProcedure
Also... is there a way to change how fast the videos playback? I would like to have the ability to show each video in full-speed, half-speed, and quarter-speed. I've looked everywhere on this forum and haven't found anything.

I want this program to be able to run under Windows, Mac and Linux.

Thankyou for reading my post.
IdeasVacuum
Always Here
Always Here
Posts: 6426
Joined: Fri Oct 23, 2009 2:33 am
Location: Wales, UK
Contact:

Re: Need help displaying videos

Post by IdeasVacuum »

Is there a special reason why you are using a windowed screen instead of simply using a window?

The movie will always play "on" a window, so if you want it to be played in a specific region, play it in it's own window, sizing that window to the size of the movie (as shown in the PB help), and then you can be very specific about the movie window's location. I assume that all your movies are the same height and width.

I did get my movies to play "on" a Canvas Gadget instead of a window - but, having worked for some time, it stopped working and so I replaced the canvas with a pop-up window as described above. Using the canvas was a hack of course, the PB help does not say it can be done anyway, but that probably would be even better for your purpose. Alternatively, the "movie window" could be border less and without a title bar, so that it would appear to be simply a region of your main window. If you are only programing for MS windows, you can use API functions to control the Z order of the movie window [SetWindowPos_()], not sure about the other OS.

Much depends on the movie format too. If you are using AVI files for example, then you could simply save each one with the range of different frame rates (number of frames per second) you require.

Another alternative approach would be to use a web gadget. You could then have, say, Flash or Animated Gif movies with the playback controls in the Gadget.
IdeasVacuum
If it sounds simple, you have not grasped the complexity.
User avatar
TI-994A
Addict
Addict
Posts: 2705
Joined: Sat Feb 19, 2011 3:47 am
Location: Singapore
Contact:

Re: Need help displaying videos

Post by TI-994A »

ron2 wrote:...i need it to play on the right side of the screen a little lower down...
Hi ron2. I'm not quite sure about the other issues, but you can position the movie screen with the ResizeMovie() function, like this:

Code: Select all

Procedure p_PlayPracticeVideo()
      If InitMovie() = 450
        MessageRequester("Error", "Can't initialize movie playback !", 0) 
        End
      Else
        If LoadMovie(450, "Videos\ASL.wmv")
          ;InitSprite()
          ;OpenWindowedScreen(WindowID(0), 780, 35, 200, 244, 0, 0, 0)
          PlayMovie(450, WindowID(0))
          ResizeMovie(450, 100, 50, 200, 244)
        Else
          MessageRequester("Error", "Can't load the movie...", 0)
        EndIf
      EndIf
EndProcedure
Is there any particular reason for the InitSprite() and OpenWindowedScreen()?
Texas Instruments TI-99/4A Home Computer: the first home computer with a 16bit processor, crammed into an 8bit architecture. Great hardware - Poor design - Wonderful BASIC engine. And it could talk too! Please visit my YouTube Channel :D
ron2
New User
New User
Posts: 6
Joined: Mon Nov 05, 2012 6:56 am

Re: Need help displaying videos

Post by ron2 »

Thankyou TI-994A - resize moved the movie to the right position on the screen

I still can't see the movie until i move the window with the mouse though
Is there any particular reason for the InitSprite() and OpenWindowedScreen()?
Not that I know of. I just spent a couple days looking at all of the code I could find on here that had anything to do with playing videos. I tried everything I could think of to get it to show a movie and the first time I was able to, this is the code I came up with.
ron2
New User
New User
Posts: 6
Joined: Mon Nov 05, 2012 6:56 am

Re: Need help displaying videos

Post by ron2 »

Is there a special reason why you are using a windowed screen instead of simply using a window?
As I understand it, if I use a window, A new window opens to play the movie and closes when it/s over. However, a windowed screen will play the movie in a section of an already opened window (which is what i need). I haven't tried a window yet thought. So I might be wrong. Tell me I'm wrong and I'll try it that way instead.
User avatar
TI-994A
Addict
Addict
Posts: 2705
Joined: Sat Feb 19, 2011 3:47 am
Location: Singapore
Contact:

Re: Need help displaying videos

Post by TI-994A »

ron2 wrote:I still can't see the movie until i move the window with the mouse though...
Hello again ron2. I'm not too familiar with these functions, but I think that the OpenWindowedScreen() function is not required for standard playback. In any case, when I used your example, my .WMV movie started automatically, and played perfectly, without any further action. This is how I implemented your procedure:

Code: Select all

Procedure p_PlayPracticeVideo()
      If InitMovie() = 450
        MessageRequester("Error", "Can't initialize movie playback !", 0) 
        End
      Else
        If LoadMovie(450, "Videos\ASL.wmv")
          PlayMovie(450, WindowID(0))
          ResizeMovie(450, 50, 50, 500, 400)
        Else
          MessageRequester("Error", "Can't load the movie...", 0)
        EndIf
      EndIf
EndProcedure

wFlags = #PB_Window_ScreenCentered | #PB_Window_SystemMenu
OpenWindow(0, 0, 0, 600, 500, "Video Playback", wFlags)
p_PlayPracticeVideo()
While WaitWindowEvent() ! #PB_Event_CloseWindow : Wend
If your movie still fails to play automatically, it could be related to either the video, or video hardware; I can't be sure.

Regarding the playback speed, the RenderMovieFrame() function looks promising, although I'm not sure how. Plus, it seems to support only MPEG video, and requires the DirectX system (from the PureBasic manual).
Texas Instruments TI-99/4A Home Computer: the first home computer with a 16bit processor, crammed into an 8bit architecture. Great hardware - Poor design - Wonderful BASIC engine. And it could talk too! Please visit my YouTube Channel :D
User avatar
TI-994A
Addict
Addict
Posts: 2705
Joined: Sat Feb 19, 2011 3:47 am
Location: Singapore
Contact:

Re: Need help displaying videos

Post by TI-994A »

ron2 wrote:As I understand it, if I use a window, A new window opens to play the movie and closes when it/s over. However, a windowed screen will play the movie in a section of an already opened window (which is what i need)...
Hi Ron. Even with this approach, you can position and play the movie anywhere on the main window, and then release it with the FreeMovie() function once the playback has finished, and reclaim the window for other uses:

Code: Select all

Procedure p_PlayPracticeVideo()
      If InitMovie() = 450
        MessageRequester("Error", "Can't initialize movie playback !", 0) 
        End
      Else
        If LoadMovie(450, "Videos\ASL.wmv")
          PlayMovie(450, WindowID(0))
          ResizeMovie(450, 50, 50, 500, 400)          
        Else
          MessageRequester("Error", "Can't load the movie...", 0)
        EndIf
      EndIf
EndProcedure

wFlags = #PB_Window_ScreenCentered | #PB_Window_SystemMenu
OpenWindow(0, 0, 0, 600, 500, "Video Playback", wFlags)

p_PlayPracticeVideo()
Delay(1000)
Repeat
  If IsMovie(450) And MovieStatus(450) = 0
    FreeMovie(450)
    MessageRequester("Movie Status:", "The playback has ended...")
  EndIf
Until WaitWindowEvent() = #PB_Event_CloseWindow
*EDIT: added a delay just before the WaitWindowEvent() loop to allow the video to load and play, and not show MovieStatus = 0
Last edited by TI-994A on Mon Nov 05, 2012 5:04 pm, edited 1 time in total.
Texas Instruments TI-99/4A Home Computer: the first home computer with a 16bit processor, crammed into an 8bit architecture. Great hardware - Poor design - Wonderful BASIC engine. And it could talk too! Please visit my YouTube Channel :D
ron2
New User
New User
Posts: 6
Joined: Mon Nov 05, 2012 6:56 am

Re: Need help displaying videos

Post by ron2 »

Thankyou TI994A. You guys are amazing. How do you find out how to do this stuff? I haven't been able to find anything that explains exactly how these commands work.

I tried your code and it works great.

I had to delete part of it in my program because it leaves another window to close after I close the main program and it won't let me show the video twice.

Code: Select all

wFlags = #PB_Window_ScreenCentered | #PB_Window_SystemMenu
OpenWindow(0, 0, 0, 600, 500, "Video Playback", wFlags)

p_PlayPracticeVideo()
Repeat
  If IsMovie(450) And MovieStatus(450) = 0
    FreeMovie(450)
    MessageRequester("Movie Status:", "The playback has ended...")
  EndIf
Until WaitWindowEvent() = #PB_Event_CloseWindow

But this part of it is exactly what I needed.

Code: Select all

Procedure p_PlayPracticeVideo()
      If InitMovie() = 450
        MessageRequester("Error", "Can't initialize movie playback !", 0) 
        End
      Else
        If LoadMovie(450, "Videos\ASL.wmv")
          PlayMovie(450, WindowID(0))
          ResizeMovie(450, 50, 50, 500, 400)          
        Else
          MessageRequester("Error", "Can't load the movie...", 0)
        EndIf
      EndIf
EndProcedure
Regarding the playback speed, the RenderMovieFrame() function looks promising, although I'm not sure how. Plus, it seems to support only MPEG video, and requires the DirectX system (from the PureBasic manual).
The RenderMovieFrame() function only works under Windows. I want to make the program available on Mac and Linux if possible. On the other hand, I do want at least a Windows version if I can't write the other 2. I made a note to look at RenderMovieFrame() later if I can't find a cross-platform solution. IdeasVacuum may have had a viable solution if nothing else works:
Much depends on the movie format too. If you are using AVI files for example, then you could simply save each one with the range of different frame rates (number of frames per second) you require.
IdeasVacuum
Always Here
Always Here
Posts: 6426
Joined: Fri Oct 23, 2009 2:33 am
Location: Wales, UK
Contact:

Re: Need help displaying videos

Post by IdeasVacuum »

... in your loop, only use FreeMovie() when the movie is no longer required. That way, you can simply have a replay button which re-activates PlayMovie(), to play back as often as desired.
IdeasVacuum
If it sounds simple, you have not grasped the complexity.
ozzie
Enthusiast
Enthusiast
Posts: 443
Joined: Sun Apr 06, 2008 12:54 pm
Location: Brisbane, Qld, Australia
Contact:

Re: Need help displaying videos

Post by ozzie »

Regarding where to play the video, in my app I play videos to canvas gadgets, using commands like

Code: Select all

PlayMovie(\nMovieNo, GadgetID(\nTargetCanvasNo))
and I've not had any problem with this. There are some movie formats that the PB Movie Library seems to have trouble with, but I don't think the problems are related to using a canvas gadget. Using separate canvas gadgets I can play several movies simultaneously.
Post Reply