May 01, 2024, 12:44:41 AM

News:

IonicWind Snippit Manager 2.xx Released!  Install it on a memory stick and take it with you!  With or without IWBasic!


Video in Dialog

Started by Pip1957, August 18, 2006, 11:03:31 AM

Previous topic - Next topic

0 Members and 1 Guest are viewing this topic.

Pip1957

Hello All

I have converted an Ibasic prog that plays a video file in a dialog which works ok only if I call the play sub from global sub main(), have tried calling from a button in on controlÂÃ,  no errors and no video anyone help please :-[


#AutoDefine "Off"
#define BUTTON_1 1
def pl as int;
def w,h,t as int;
def vfile as string;
def stat as string;
DECLARE import,mciSendStringA(lpszCommand as STRING,lpszReturnString as STRING,cchReturn as INT,hwndCallback as INT),INT;ÂÃ, 
class dlg:CDialog
{
declare OnInitDialog(),int;
declare OnClose(),int;
declare OnControl(int nID, int nNotifyCode, unsigned int hControl),int;
}
global sub main()
{
dlg d1;
d1.Create(0,0,470,410,0x80C80080,0,"Caption",0);
d1.AddControl(CTDEFBUTTON,"Button1",200,348,70,20,0x50000001,0x0,BUTTON_1);
vfile=filerequest("Load File",d1,1,"Movie Files (*.mpg)|*.mpg|Movie Files (*.avi)|*.avi||","mpg");
if(vfile<>"")
{
GetAviInfo(vfile,w,h,t);
d1.showdialog();
pl=PlayAvi(d1,vfile,10,5,250,200);
}
else
{
messagebox(0,"No File Selected","Error");
}
do{ wait(); }until d1.m_hwnd = 0;
return 0;
}
dlg::OnClose(),int
{
if (pl) CloseAvi();
CloseDialog(1);
return true;
}
dlg::OnInitDialog(),int
{
dlg d1;
CenterWindow();
return true;
}
dlg::OnControl(int nID, int nNotifyCode, unsigned int hControl),int
{
dlg d1;
select nID
{
case BUTTON_1:
if(nNotifyCode = 0)
{

}
}
return true;
}
Sub PlayAvi(win as Cwindow,fn as string,x as int,y as int,w as int,h as int),int
{
dlg d1;
ÂÃ,  ÂÃ, def wi as int;
ÂÃ,  ÂÃ, def wp as string;
ÂÃ,  ÂÃ, wp = using("# Style #", win.m_hwnd, 0x40000000);
ÂÃ,  ÂÃ, if (mciSendStringA("open \""+fn+"\" type Mpegvideo alias myvideo parent "+wp, "", 0, 0)=0)
{
ÂÃ,  ÂÃ,  ÂÃ,  if (mciSendStringA(using("put myvideo window at # # # #", x, y, w, h), "", 0, 0)=0)
{
ÂÃ,  ÂÃ,  ÂÃ,  ÂÃ,  ÂÃ, if (mciSendStringA("play myvideo", "", 0, 0)=0)
{
d1.setcaption("Width: = "+numtostr(w)+" Height: = "+numtostr(h)+" Time in secs: = "+numtostr(t/1000));
ÂÃ,  ÂÃ,  ÂÃ,  ÂÃ,  ÂÃ,  ÂÃ,  return 1;
ÂÃ,  ÂÃ,  ÂÃ,  ÂÃ,  ÂÃ, }
}
ÂÃ,  ÂÃ,  ÂÃ,  else
{
ÂÃ,  ÂÃ,  ÂÃ,  ÂÃ,  ÂÃ, CloseAvi();
}
ÂÃ,  ÂÃ,  }
ÂÃ,  ÂÃ, return 0;
}

Sub GetAviInfo(fn as string,w as int byref,h as int byref,t as int byref),int
{
ÂÃ,  ÂÃ, def c,r AS string;
ÂÃ,  ÂÃ, def n as int;
ÂÃ,  ÂÃ, c = "open \"" + fn + "\" type mpegvideo alias myvideo";
ÂÃ,  ÂÃ, if (mciSendStringA(c,"",0,0)=0)
{
ÂÃ,  ÂÃ,  ÂÃ,  mciSendStringA("Where myvideo destination", stat,128,0);
ÂÃ,  ÂÃ,  ÂÃ,  stat=strmid(stat,5);
ÂÃ,  ÂÃ,  ÂÃ,  n=strfind(stat," ");
ÂÃ,  ÂÃ,  ÂÃ,  w=strtonum(strleft(stat,n-1));
ÂÃ,  ÂÃ,  ÂÃ,  h=strtonum(strmid(stat,n+1));
ÂÃ,  ÂÃ,  ÂÃ,  mciSendStringA("set myvideo time format ms","",0,0);
ÂÃ,  ÂÃ,  ÂÃ,  mciSendStringA("status myvideo length",stat,255,0);
ÂÃ,  ÂÃ,  ÂÃ,  t=strtonum(stat);
ÂÃ,  ÂÃ,  ÂÃ,  CloseAvi();
}
ÂÃ,  ÂÃ, else
{
ÂÃ,  ÂÃ,  ÂÃ,  return 0;
ÂÃ,  ÂÃ, }

ÂÃ,  ÂÃ, return 1;
}
Sub CloseAvi()
{
ÂÃ,  ÂÃ, mciSendStringA("close myvideo", "", 0, 0);
ÂÃ,  ÂÃ, return;
}


Ionic Wind Support Team

Let's see.

You have "dlg d1" defined in your PlayAVI subroutine, and your OnContro subroutinel, which are not doing anything for you since they are local variables and not the one you create in main.

Learn about the "this" pointer.  For example if you were to call the PlayAVI subroutine from within a method of the dlg class then 'this' points to the instance of that class.  In otherwords the variable you used to create the dialog.


dlg::OnControl(int nID, int nNotifyCode, unsigned int hControl),int
{
    //dlg d1;  NO!!!!!!
    select nID
    {
          case BUTTON_1:
          if(nNotifyCode = 0)
          {
               PlayAVI(this,.....
          }
     }
return true;
}


And then change your PlayAVI subroutine to use a pointer.


Sub PlayAvi(CWindow *win,fn as string,x as int,y as int,w as int,h as int),int
{
//dlg d1;  NO!!!!!!
   def wi as int;
   def wp as string;
   wp = using("# Style #", win->m_hwnd, 0x40000000);
   if (mciSendStringA("open \""+fn+"\" type Mpegvideo alias myvideo parent "+wp, "", 0, 0)=0)
{
      if (mciSendStringA(using("put myvideo window at # # # #", x, y, w, h), "", 0, 0)=0)
{
         if (mciSendStringA("play myvideo", "", 0, 0)=0)
{
win->setcaption("Width: = "+numtostr(w)+" Height: = "+numtostr(h)+" Time in secs: = "+numtostr(t/1000));
            return 1;
         }
}
      else
{
         CloseAvi();
}
    }
   return 0;
}


Play around, you'll get it.
Ionic Wind Support Team

Pip1957

Cheers paul it does sink in slowly ;D