Envision, Create, Share

Welcome to HBGames, a leading amateur game development forum and Discord server. All are welcome, and amongst our ranks you will find experts in their field from all aspects of video game design and development.

playing videos in the game

Hi , i would like to know if it's possible with default options or using a script to play a videoclip as an event during the game.
Thank you
 
Yes it is.... Here you go:

Code:
class Scene_Movie
##Copy this into a new section of your game. 
##To play a file, move the avi file into a "movies" subdirectory (yourgame\data, 
##yourgame\graphics, yourgame\movies). 
##Then call "Scene_Movie.new(filename)" where filename is your movies actual filename
## (minus the .avi).         exp Scene_Movie.new("???")
## If you want to play multiple movies in a row 
##(for example before the game starts, maybe a "developed by", "produced by", "intro movie"
## set or something... Go to the "main" section of code and find the line "$scene = Scene_Title.new". 
##Just after that line add:
##CODE
##Scene_Movie.new("dev_by")
##Scene_Movie.new("pro_by")
##Scene_Movie.new("intro")
##$scene = Scene_Movie.new("intro",8,false)assuming the filename of the intro movie is "intro.avi" and it's 8 seconds long.
##class Scene_Movie
 def initialize(movie)
   @readini = Win32API.new 'kernel32', 'GetPrivateProfileStringA', %w(p p p p l p), 'l'
   @movie_name = Dir.getwd()+"\\Movies\\"+movie+".avi"
   main
 end
 
 def main

   game_name = "\0" * 256
   @readini.call('Game','Title','',game_name,255,".\\Game.ini")
   game_name.delete!("\0")
   @wnd = Win32API.new('user32','FindWindowEx','%w(l,l,p,p)','L')
   @temp = @wnd.call(0,0,nil,game_name).to_s
   movie = Win32API.new('winmm','mciSendString','%w(p,p,l,l)','V')
   movie.call("open \""+@movie_name+"\" alias FILE style 1073741824 parent " + @temp.to_s,0,0,0)
   @message = Win32API.new('user32','SendMessage','%w(l,l,l,l)','V')
   
   @detector = Win32API.new('user32','GetSystemMetrics','%w(l)','L')
   @width = @detector.call(0)
   if @width == 640
     fullscreen
     Graphics.update
     sleep(1)
     Graphics.update
     sleep(1)
     Graphics.update
     sleep(1)
   end
   
   status = " " * 255
   movie.call("play FILE",0,0,0)
   loop do
    sleep(0.1)
    @message.call(@temp.to_i,11,0,0)
    Graphics.update
    @message.call(@temp.to_i,11,1,0)
    Input.update
    movie.call("status FILE mode",status,255,0)
    true_status = status.unpack("aaaa")
    if true_status.to_s != "play"
      break
    end
    if Input.trigger?(Input::B)
      Input.update
      break
    end
   end
   movie.call("close FILE",0,0,0)
   bail
 end
 
 def bail
   if @width == 640
     fullscreen
   end
  end
end

def fullscreen()
 
 $full.call(18,0,0,0)
 $full.call(13,0,0,0)
 $full.call(18,0,2,0)
 $full.call(13,0,2,0)
end
$full = Win32API.new('user32','keybd_event','%w(l,l,l,l)','')

Good luck...
 
dont even need that lol
just put it in the bgs folder
then use an event to play bgs and choose the video that you want to play :)
provided that is its an avi format vid, not sure hwta others play
 
crispychaney;229290 said:
dont even need that lol
just put it in the bgs folder
then use an event to play bgs and choose the video that you want to play :)
provided that is its an avi format vid, not sure hwta others play

The way you describe opens a new window and interupts the game. The script I provided actually has the video play in game withOUT opening it in another window.

One problem is that the video automatically makes the game windowed if in fullscreen and you can't go back to fullscreen until the movie is over, or you skip it, without some major flickering.

I use the above script for my game. I like it.
 
for the window is not a problem...where must paste the script?it goes under a particular script or i can make it everywhere in the script page?
and how do i make a movie start during the game?

thank you


Umm edit ... i've read the brief guide in the script but i still don't know how to call the video...
i have a video.avi in the folder "movies" but i don't know what kind of commands should i give to the event on the map , maybe "script" command but i didn't understant what i must write in the window ,sorry but i never used this command

UPDATES:

I made a event with the "Script" command and i wrote Scene_Movie.new("movie1")
movie1.avi is the name of the video.
But when i activate the event it plays just the audio of my movie
what's wrong?
 
I made a event with the "Script" command and i wrote Scene_Movie.new("movie1")
movie1.avi is the name of the video.
But when i activate the event it plays just the audio of my movie
what's wrong?

That's a codec problem. You'll need the right codec to play the movie. I know your going to say that the movie plays fine outside of RMXP, but to play it in RMXP you need the codec.

I suggest rerendering the video using a video editting program [movie maker is free and comes with windows if your using windows] under the "Cinepak Codec by Raduis". The video should now be in a format that anybody can view since Cinepak is an extremely common codec.

If that doesn't float your boat, you can search the interent for the very handy codec packs that are out there. Most of them are free.
 
mmm i hope it will not make conflicts with CCCP (combined community codec pack).
But everyone plays my game then should have the same codecs to see the video?
if it's so, i'll have to make a setup file for the game
 
Well I'm not sure about the Codec pack you have, but I put all my Avi's in the Cinepack Codec.

You can also put them in .WMV format if that will be easier to do. In fact I would do that. The file size will be smaller and the movie will be able to be played pretty much no matter what.

Take the line below that's bolded and change the .avi to .wmv

Code:
##class Scene_Movie
 def initialize(movie)
   @readini = Win32API.new 'kernel32', 'GetPrivateProfileStringA', %w(p p p p l p), 'l'
   [B]@movie_name = Dir.getwd()+"\\Movies\\"+movie+".avi"[/B]
   main
 end

To

Code:
##class Scene_Movie
 def initialize(movie)
   @readini = Win32API.new 'kernel32', 'GetPrivateProfileStringA', %w(p p p p l p), 'l'
   [B]@movie_name = Dir.getwd()+"\\Movies\\"+movie+".wmv"[/B]
   main
 end
 
Hi there ,i've tried to download a cinepak codec , it was not by radius ,but it was the only one i found,
anyway
I suggest rerendering the video using a video editting program [movie maker is free and comes with windows if your using windows] under the "Cinepak Codec by Raduis". The video should now be in a format that anybody can view since Cinepak is an extremely common codec.
how can i do this? i'm not so good in video editing
thank you for your help
 
psychochild;231459 said:
Hi there ,i've tried to download a cinepak codec , it was not by radius ,but it was the only one i found,
anyway

how can i do this? i'm not so good in video editing
thank you for your help

It's really easy to do.

1. Open Movie Maker.
2. On the left hand side of the screen at the top is the option "Import Video". Click it.
3. Find your video in the Diaglog box that appears and click "Import".
4. Movie Maker will automatically cut the imported movie into little pieces [this is an option you can turn off I think]. Select all the pieces and put them in the timeline at the bottom of the screen.
5. Go to the third movie task at the top left of the screen. It's the one called "Finish Movie". Click the Option "Save to My Computer".
6. Now all you have to do is follow the prompts [Enter a Name and destination, etc.].
7. When you get the option that says best quality, click the blue "Show More Choices" button and click other settings. Now just pick the setting you want. I suggest "High Quality Video (Large)".
8. Finally you just click Next and Movie Maker will do the rest. It's that simple.



If you ahve anymore questions don't hesitate to ask.
 
Thank you so much... but still nothing , it still plays just audio...now i'm downloading ACE Mega CodecS Pack 6.03 - Professional Edition almost 50 Mb of codecs , cinepak included... let's see who will win now :thumb:
If my pc will not explode with all these codecs . . . :s

Edit :
Not even this huge codec pack has solved the problem, the event activates , the music of the video starts but i still see the game screen stopped...i'm starting to give up hope :(
 
psychochild;233747 said:
Thank you so much... but still nothing , it still plays just audio...now i'm downloading ACE Mega CodecS Pack 6.03 - Professional Edition almost 50 Mb of codecs , cinepak included... let's see who will win now :thumb:
If my pc will not explode with all these codecs . . . :s

Edit :
Not even this huge codec pack has solved the problem, the event activates , the music of the video starts but i still see the game screen stopped...i'm starting to give up hope :(


That's extremely wierd. The movie plays fine outside of RMXP?
 
TRY THIS:
Code:
class Scene_Movie

def initialize(movie,length,exit_to_game=true)
  @readini = Win32API.new 'kernel32', 'GetPrivateProfileStringA', %w(p p p p l p), 'l'
  @movie_name = Dir.getwd()+"\\Movies\\"+movie+".avi"
  @counter = length*10
  @exit_to_game = exit_to_game
  main
end

def main
  game_name = "\0" * 256
  @readini.call('Game','Title','',game_name,255,".\\Game.ini")
  game_name.delete!("\0")
  Graphics.transition
  @wnd = Win32API.new('user32','FindWindowEx','%w(l,l,p,p)','L')
  @temp = @wnd.call(0,0,nil,game_name).to_s
  @movie = Win32API.new('winmm','mciSendString','%w(p,p,l,l)','V')
  @movie.call("open \""+@movie_name+"\" alias FILE style 1073741824 parent " + @temp.to_s,0,0,0)
  @message = Win32API.new('user32','SendMessage','%w(l,l,l,l)','V')
  
  @detector = Win32API.new('user32','GetSystemMetrics','%w(l)','L')
  @width = @detector.call(0)
  if @width == 640
    fullscreen
    Screen::update
    sleep(1)
    Screen::update
    sleep(1)
    Screen::update
    sleep(1)
  end
  
  @movie.call("play FILE",0,0,0)
  loop do
   sleep(0.1)
   @message.call(@temp.to_i,11,0,0)
   Graphics.update
   @message.call(@temp.to_i,11,1,0)
   Input.update
   if Input.trigger?(Input::B)
     Input.update
     break
   end
   @counter = @counter - 1
   if @counter <= 0
     break
    end
  end
  @movie.call("close FILE",0,0,0)
  if @exit_to_game
    $scene = Scene_Map.new
  else
    $scene = nil
  end
  Graphics.freeze
  if @width == 640
    fullscreen
  end
end
end

def fullscreen()

$full.call(18,0,0,0)
$full.call(13,0,0,0)
$full.call(18,0,2,0)
$full.call(13,0,2,0)
end
$full = Win32API.new('user32','keybd_event','%w(l,l,l,l)','')
 
Ok ,thank you , now the error problem is solved ,but it still plays just music and not video .
Now as firestaker5 said , it's a codec problem,but i really don't know what codecs i can use to solve it , i've tried a lot of codecs with no results...can you tell me what video codecs do you use?
 
I tried the script, using a wmv, but when I go in i doesn't do anything. It just freezes. It's so annyoing because I've attempted the same thing b4 with an avi, but I had a codec problem. But this movie plays fine outside of the game...
 

Thank you for viewing

HBGames is a leading amateur video game development forum and Discord server open to all ability levels. Feel free to have a nosey around!

Discord

Join our growing and active Discord server to discuss all aspects of game making in a relaxed environment. Join Us

Content

  • Our Games
  • Games in Development
  • Emoji by Twemoji.
    Top