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.

Help with AVI player for RMXP

Hello.

I want someone to help me fix a problem with how the AVI player works for my game.

It works fine when I play the movies before the Title Screen. But when I play the movie after selecting a new game, it stops at the end and doesn't load the next scene/map.

This is the script that I am using:

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)','')

And this is where I placed the supposedly opening movie after selecting a new game from the Title Screen:

Code:
   # Move player to initial position
$scene = Scene_Movie.new("OP",178,true)    
$game_player.moveto($data_system.start_x, $data_system.start_y)

It's in the Scene_Title.

I have already tried placing an event on a map to play this op movie but it doesn't work. Also, when I press the 'X' and the ESC key on the keyboard, the movie ends but then it shows the title screen for a couple of seconds before proceeding to the map.

Can someone please help me fix this problem?
 
Hi,

I am no scripter, I have no idea why does your problem happen.

However, I do know you're using an older version of the avi player.
Here's a more modern one:
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)','')

It doesn't have the problems you mentioned. You also do not need to specify its duration.
Just call it with Scene_Movie.new("YOUR_FILE") - from \Movies.
The only problem is that it flickers at fullscreen and it has a bit of lag during playing the video. If there's something better than this script, I'd like to know about it too...

Hope this helps :)
 
I've tried this as well, but the same problem happens. What's more, when I hit the ESC key, the movie plays over again and only when I have pressed the ESC key twice does it stop the movie from playing...
 
Sakura Martinez;312311 said:
I've tried this as well, but the same problem happens. What's more, when I hit the ESC key, the movie plays over again and only when I have pressed the ESC key twice does it stop the movie from playing...

That's weird... it could have something to do with the codec... or maybe your windows version, or the path you've put your project in(as for the last one, I've been there)...

Old divx codecs are no good with this script. As for the windows version, I'm just guessing. As for the last, I've been using a path with non-ascii characters(in case you don't know, that basically means those who don't exist in the english keyboard layout) and the script couldn't work.

If none of these is any good... well... do you use any more scripts besides this that could cause conflicts?

My best shot is the video codec, though. Which one do you use for your video?
 
Well, I made my videos by using Windows Movie Maker in XP SP2, then I convert the videos into AVI format using Xillsoft's Converter.

As for the scripts, I have the cutscene script, the advance weather effects script, the advance message script, and a bunch of other scripts that I forgot (I'm using the school computer so I can't look up on my project at the moment).

I doubt it is the codec though. I've tested a lot of codecs and the one I'm using now (from the Converter) is the one that actually works (compared to the others I have tried).
 
I'm running out of ideas...

Come to think of it, since it works as it should at the intro and not in the map, it SHOULD be a script error. (If it is, it could be the cutscene one)

This will definitely be of some service:
Create a new, raw project without any scripts in it. Put the movie script in it and try it in there. If the movie works properly, you will have to find which script causes the malfuction and remove it(or try to modify it, possibly decreasing its functionality-or I could try as well, I'm no scripter, but I've done this thing before for my project-).

(If again, this doesn't work, try at another computer or encode the video with another program. Windows XP SP2 is what I use too, and it works for me. But, again, which codec did you use?)
 
I'll try that now... As for the codec, I'm using mpeg4. Another question, by the way, I'm still confused as to the true and false after the number of seconds where you call the movie. Can you explain that? Maybe my problem is there...

EDIT: I've tried it, the problem still exists. Whenever I try to skip the movie, it still loops over and I have to press the ESC key again just to end it.
 
Sakura Martinez;313291 said:
I'll try that now... As for the codec, I'm using mpeg4. Another question, by the way, I'm still confused as to the true and false after the number of seconds where you call the movie. Can you explain that? Maybe my problem is there...

EDIT: I've tried it, the problem still exists. Whenever I try to skip the movie, it still loops over and I have to press the ESC key again just to end it.

The true/false explains in your script "exit to game". I'm not sure what that means, but it sounds like it could have something to do with that...

By the way, have you tried both the old and the new version of the script?
 
Exit the game? To where? to the Title Screen?

I've tried the old and new versions before I posted here since I wanted to make sure that I really can't do it by myself before I ask for help.

Anyway, what do I need to do so that if I skip the movie it won't show the title screen before continuing on to the second event? That's the main problem I have now...

(sorry for the questions...)
 
I really can't think of anything else... the new script works almost perfectly with me...although the old one repeats the movie for one time if skip it with ESC-I tried it just now-...

I have no idea on how to fix the title thing...
As for the "exit to game", it's written on your script, I don't know what it means...

My last idea: Try in another pc with a different video... just to find if there are any circumstances in which it will work...

If you already tried everything I said, it's a total mystery to me as to why nothing works.

I'm sorry my solutions are no good. We really need a more experienced guy to take it over from here...
 
Hm...

I've tried using another computer with the old script but the effect is still the same...
Ive tried using the new script again, but everytime the pre-title screen movie plays, it loops at the end of the video (the last 2 seconds of it, i think) and unless I press the 'X' key on the keyboard it wouldn't stop.

This really bums me out. Thanks for trying to help, though...^_^
 
Just in case nobody else checks this thread, I could make a suggestion...

Can't you replace your video with a slideshow(by making a sequence of jpegs via the "display picture" command) accompanied by a bgm, or an ordinary cutscene?
 
I've only skimmed this thread, but I can tell you that I have used this script a lot in my game.

The problem you describe is not a codec problem [the codec problem is usually just a black screen with the sound playing]. What I believe the problem is... Well that you have the movie playing in a wierd way.

If you want a movie to play before the titlescreen you put in "Main" of the script Editor, right after the Begin.

If you want the movie to play after you hit "New Game" you put it on the starting map with an "AutoStart" event. Make the map blank [nothing on it but the event] and then add a teleport after the "Call Script" with the movie in it. This means when you hit "New Game" you will automatically be sent to the movie and when the movie ends you will be telported to the game.

You sound as if you were putting a movie code in the "Scene_Title" of the script editor. This will obviously not work and in fact is the cause of your "multiple" playing problem. The game is replaying the movie over again after you skip it because it doesn't have the end command.

If you place the movie like I have suggested above [in the event] then the movie will be called using the script and will have a end command.

Feel free to PM me if you have any questions. I have gone through just about every problem you can think of with this script and I have finally got a handle on it. I should be able to help you.

feel free to PM me,
Firestalker
 
Thanks, Firestalker5, I already sent you a PM, but what the heck, I'll post it here as well...

I did what you said and now it plays the movie fine but at the end of the movie it shows the title screen before continuing on with the rest of the event. Any idea on how to fix this? Thanks in advance... ^_^
 

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