Friday, January 1, 2016

Working with video and audio from Visual Foxpro


This is maybe a first view from visual foxpro of the video&audio world from FFMPEG , a fabulous open source. I insert more than 30 codes to do many operations on any media.The majority of codes can accessed in the projectt. I joigned the last vesrion of ffmpeg.exe (can download for free but warning to the updates it can confuse). This is the first and alpha version.Please report any bug. thanks Author: Yousfi Benameur  Freeware 10.6MB Last updated: 2013.11.09

HTML Video Player Automation

*Begin Code
Publi yform,yvideo
yform=Newobject("yhtml5Player")
yform.Show
Read Events
Return
*
Define Class yhtml5Player As Form
    Height = 631
    Width = 940
    ShowWindow = 2
    ShowTips = .T.
    AutoCenter = .T.
    Caption = "HTML video/audio Player automation"
    Name = "Form1"

 

    Add Object obrowser As OleControl With ;
        oleclass="shell.explorer.2",;
        Top = 45, ;
        Left = 247, ;
        Height = 560, ;
        Width = 677, ;
        Anchor = 0, ;
        Name = "oBrowser"

    Add Object command1 As CommandButton With ;
        Top = 82, ;
        Left = 22, ;
        Height = 36, ;
        Width = 156, ;
        FontBold = .T., ;
        Caption = "Create /Fill  the player", ;
        BackColor = Rgb(255,128,0), ;
        Name = "Command1"

    Add Object command4 As CommandButton With ;
        Top = 473, ;
        Left = 132, ;
        Height = 25, ;
        Width = 30, ;
        FontBold = .T., ;
        Caption = "Vol+", ;
        BackColor = Rgb(0,255,0), ;
        Name = "Command4"

    Add Object command5 As CommandButton With ;
        Top = 473, ;
        Left = 161, ;
        Height = 25, ;
        Width = 30, ;
        FontBold = .T., ;
        Caption = "Vol-", ;
        BackColor = Rgb(0,255,0), ;
        Name = "Command5"

    Add Object command9 As CommandButton With ;
        Top = 473, ;
        Left = 190, ;
        Height = 25, ;
        Width = 34, ;
        FontBold = .T., ;
        Caption = "Mute", ;
        BackColor = Rgb(0,255,0), ;
        Name = "Command9"

    Add Object command8 As CommandButton With ;
        Top = 420, ;
        Left = 112, ;
        Height = 37, ;
        Width = 128, ;
        FontBold = .T., ;
        FontSize = 10, ;
        Caption = "Show/Hide controls", ;
        BackColor = Rgb(0,255,0), ;
        Name = "Command8"

    Add Object command11 As CommandButton With ;
        Top = 420, ;
        Left = 2, ;
        Height = 37, ;
        Width = 109, ;
        FontBold = .T., ;
        FontSize = 10, ;
        Caption = "Change Poster", ;
        BackColor = Rgb(0,255,0), ;
        Name = "Command11"

    Add Object command12 As CommandButton With ;
        Top = 372, ;
        Left = 48, ;
        Height = 25, ;
        Width = 132, ;
        FontBold = .T., ;
        FontSize = 10, ;
        Caption = "Video Infos", ;
        BackColor = Rgb(0,255,0), ;
        Name = "Command12"

    Add Object edit1 As EditBox With ;
        Height = 241, ;
        Left = 10, ;
        ReadOnly = .T., ;
        ScrollBars = 2, ;
        Top = 125, ;
        Width = 228, ;
        BackColor = Rgb(255,255,159), ;
        DisabledBackColor = Rgb(255,255,128), ;
        Name = "Edit1"

    Add Object command13 As CommandButton With ;
        Top = 468, ;
        Left = 3, ;
        Height = 36, ;
        Width = 123, ;
        FontBold = .T., ;
        FontSize = 12, ;
        Caption = "Play/Pause", ;
        BackColor = Rgb(0,255,0), ;
        Name = "Command13"

    Add Object text1 As TextBox With ;
        FontBold = .T., ;
        Height = 25, ;
        Left = 12, ;
        Top = 516, ;
        Width = 144, ;
        ForeColor = Rgb(0,255,0), ;
        BackColor = Rgb(0,0,0), ;
        Name = "Text1"

    Add Object timer1 As Timer With ;
        Top = 504, ;
        Left = 120, ;
        Height = 23, ;
        Width = 23, ;
        Enabled = .F., ;
        Interval = 1000, ;
        Name = "Timer1"

    Add Object command7 As CommandButton With ;
        Top = 2, ;
        Left = 14, ;
        Height = 27, ;
        Width = 49, ;
        FontBold = .T., ;
        Caption = "....", ;
        MousePointer = 15, ;
        ToolTipText = "Get a valid video or audio file or ur type an URL in textbox", ;
        ForeColor = Rgb(255,0,0), ;
        BackColor = Rgb(0,255,0), ;
        Name = "Command7"

    Add Object yvid As TextBox With ;
        FontSize = 11, ;
        Height = 27, ;
        Left = 69, ;
        Top = 1, ;
        Width = 841, ;
        Name = "yVid"

    Add Object yhelp As Label With ;
        FontSize = 16, ;
        Fontbold=.T.,;
        caption="?",;
        backstyle=0,;
        forecolor=255,;
        mousepointer=15,;
        tooltiptext="Summary help",;
        Height = 27, ;
        Left = 915, ;
        Top = 1, ;
        Width = 22, ;
        Name = "yhelp"

    Add Object combo1 As ComboBox With ;
        Height = 27, ;
        Left = 25, ;
        ToolTipText = "Media Library", ;
        Top = 41, ;
        Width = 181, ;
        Name = "Combo1"

    Procedure Destroy

   try
    yvideo=null
    yvideo release
    catch
    endtry
        Clea Events
    Endproc

    Procedure Load
        Declare Integer Sleep In kernel32 Integer
        Set Safe Off
    Endproc

    Procedure Init
        Thisform.SetAll("mousepointer",15,"commandbutton")
    Endproc

    Procedure obrowser.Init
        Local m.myvar
        TEXT to m.myvar noshow
        
        
        
        

        
        
        ENDTEXT
        Local m.lcdest
        m.lcdest=Addbs(Sys(2023))+"yvid.html"
        Strtofile(m.myvar,m.lcdest)

        This.Navigate(m.lcdest)
    Endproc

    Procedure command1.Click
        oo=Thisform.obrowser.Document
        If !Vartype(m.oo)="O"
            Return .F.
        Else
        Endi


        If Empty(Thisform.yvid.Value)
            Messagebox("get a video file or url first!",16+4096,"",1500)
            Return .F.
        Endi

        With Thisform.obrowser.Document
            .body.Scroll="no"
            .bgcolor=0
            Sleep(600)
            If !Vartype(yvideo)="O"
                   yvideo=.createElement("video")
                .body.appendChild(yvideo)
                With  yvideo
                    .Id ="yvideo1"
                    .autoPlay=.F.
                    .Controls=.T.
                    .poster=  "http://www.spacetelescope.org/static/archives/images/screen/potw1441a.jpg"
                    .Width =Thisform.obrowser.Width-10
                    .Height=Thisform.obrowser.Height-20
                Endwith
            Endi

            With yvideo
                .src=""
                .src = Thisform.yvid.Value
                .Load(.src)
            Endwith
            Sleep(1000)  && to load the video and retrieve  correctly some data wanted

            With Thisform
                .text1.Value=""
                .edit1.Value=""
                .command12.Click()
            Endwith

        Endwith

    Endproc

    Procedure command4.Click
        Try
            With Thisform.obrowser.Document.getElementById("yvideo1")
                x=.Volume
                If .Volume<=0.9
                    .Volume=.Volume+.1
                Endi
            Endwith
        Catch
        Endtry
    Endproc

    Procedure command5.Click
        Try
            With Thisform.obrowser.Document.getElementById("yvideo1")
                x=Trans(.Volume)
                If .Volume>=0.1 And .Volume<=1
                    .Volume=.Volume-.1
                Endi
            Endwith
        Catch
        Endtry
    Endproc

    Procedure command9.Click
        Try
            With Thisform.obrowser.Document.getElementById("yvideo1")
                .muted=!.muted
            Endwith
        Catch
        Endtry
    Endproc

    Procedure command8.Click
        With Thisform.obrowser.Document.getElementById("yvideo1")
            .Controls=Iif(.Controls=.T.,.F.,.T.)
        Endwith
    Endproc

    Procedure command11.Click
        With Thisform.obrowser.Document.getElementById("yvideo1")
            .poster=Getpict()
        Endwith
    Endproc

    Procedure command12.Click
        cr=Chr(13)
        Try
            With Thisform.obrowser.Document.getElementById("yvideo1")
     text to thisform.edit1.value textmerge noshow
 -Video=<<.src>>
 -Poster=<<.poster>>
 -Duration=<<  Trans(.duration,'999999.99')>>  sec.
 -Widh  =<> px
 -Height=<> px
           endtext

                Endwith
        Catch
        Endtry
    Endproc

    Procedure command13.Click
        Thisform.obrowser.Document.Script.playPause("")   &&executed in condition this script function must be the first in document object scripts
        Thisform.timer1.Enabled=.T.
    Endproc

    Procedure timer1.Timer
        With Thisform.obrowser.Document.getElementById("yvideo1") 

Thisform.text1.Value=Trans[.currentTime(),"999999.99"]+"/"+;
Trans(.duration,"999999.99")+" Sec."
            If .ended=.T. Or .paused
                This.Enabled=.F.
            Endi
        Endwith
    Endproc

    Procedure command7.Click
        Local m.xvideo
        m.xvideo=Getfile('mp4')
        Thisform.yvid.Value=m.xvideo
    Endproc

    Procedure combo1.Click
        Thisform.yvid.Value=This.Value
    Endproc

    Procedure combo1.Init
        With This
            .AddItem("http://ie.microsoft.com/testdrive/ieblog/2011/nov/pp4_blog_demo.mp4")
            .AddItem("http://ie.microsoft.com/testdrive/Videos/BehindIE9AllAroundFast/video.mp4")
            .AddItem("http://www.broken-links.com/tests/media/BigBuck.m4v")
            .AddItem("http://unheardbeethoven.org/defunct/Fifth%20Symphony.mp3")
            .AddItem("http://www.symphozik.info/multi/beethoven/6.mp3")
            .AddItem("http://corpsyphonie.free.fr/documents/melodies/Nocturnes/Mozart_NocturneI_Soprano1.mp3")
            .ListIndex=1
            .Style=2
        Endwith
    Endproc

    Procedure yhelp.Click
        Local m.myvar
        TEXT to m.myvar noshow
Get a video or audio valid file on disc or chose in the library(combo), then create/fill the player button.
the code create by automation the video/audio player in the vfp browser (mandatory with emulation as ie11 to support
 the html5).
you can do these things:

-play/pause button the media.this i cannot make it by automation (play, pause dont work from vfp.it works  only from javascript !).i made a script in the navigated file and automate it from vfp.
-return informations from the media file(src,duration), the width/height of the media
-can adjust the volume + or - or mute
-can show /hide the controls.
-can change the poster (any image from disc or from the web)
-A timer measure the currentTime of the media and fills a textbox.
-this is the basics.CAn extend to advanced things....
On IE the media supported actually on html5 vide/audio : mp4,mp3 for sure.can try others (a message is shown on the control bar).

The duration information is well returned when media is loaded(click the button).

 ENDTEXT

        Messagebox(m.myvar,0+32+4096,"Summay help")

    Endproc
Enddefine
*
*-- EndDefine: yhtml5Player
*END CODE
}






No comments:

Post a Comment