Jump to content

PlayYoutube Videos (sort of working code included)


RobYost

Recommended Posts

I have a procedure that works at playing Youtube videos.  But it only works if you are on the same computer as the UniGUI program that is running.l

 

I put it on my server and when on the server it works, but if I try from across the internet it does not.

 

Is there a port that needs to be opened?

 

(Video is a TUniHTMLFrame)
procedure TfrmModal.ShowVideo(VideoName: string; VideoWidth: Integer; VideoHeight: Integer);
var
  sql: TSQL;
begin

  frmModal.Height := VideoHeight + GetSystemMetrics(SM_CYCAPTION);
  frmModal.Width  := VideoWidth;

  sql.Add('<html>');
  sql.Add('<head>');
  sql.Add('</style>');
  sql.Add('    <style type="text/css">.recentcomments a{display:inline !important;padding:0 !important;margin:0 !important;}</style>');
  sql.Add('</head>');
  sql.Add('<body>');
  sql.Add('  <object width="' + itoa(VideoWidth) + '" height="' + itoa(VideoHeight) + '">');
  sql.Add('  <param name="movie" value="http://www.youtube.com/v/fqNHsmGCEDI&hl=en_US&feature=player_embedded&version=3">');
  sql.Add('  </param><param name="allowFullScreen" value="true">');
  sql.Add('  </param><param name="allowScriptAccess" value="always">');
  sql.Add('  </param><embed src="http://www.youtube.com/v/' + VideoName +
    '&hl=en_US&feature=player_embedded&version=3" type="application/x-shockwave-flash" sql.Add('');allowfullscreen="true" allowScriptAccess="always">');
  sql.Add('  </embed></object>');
  sql.Add('</body>');
  sql.Add('</html>');

  Video.Align   := alClient;
  Video.Enabled := True;
  Video.HTML.Clear;
  Video.HTML.Add(sql.Text);

end;
Link to comment
Share on other sites

I just noticed I used a Type that I wrote:

 

TSQL

 

I created it so I wouldn't have to create and free TStringList,  and the text property is useful when debugging 'Copy Value' does not have any CR LF in it so I can paste it to SQL Server.

 

You can replace the TSQL with TStringList (but you have to create it)

 

I will include the TSQL Source if anyone is interested in it.  Let me know if you see a problem with it.

 

type
  TSQL = record
  private
    FItems: array of string;
    FText : String;

    function GetCount: integer; inline;
    function GetText: String; inline;

    function GetItem(index: integer): string;
    procedure SetItem(index: integer; const Value: string);

  public
    property Text : string read GetText;
    property Count: integer read GetCount;

    function Add(const line: string): integer;
    procedure Clear;
    function IndexOf(const s: string): integer;

    property Items[index: integer]: string read GetItem write SetItem; default;
  end;
// =============================================================================
function TSQL.Add(const line: string): integer;
begin
  SetLength(FItems, Count + 1);
  FItems[Count - 1] := line;
  Result            := Count - 1;
  FText             := Text;
end;

// =============================================================================
function TSQL.GetCount: integer;
begin
  Result := length(FItems);
end;

// =============================================================================
function TSQL.GetText: String;
var
  i: integer;
begin
  for i    := 0 to Count - 1 do
    Result := Result + ' ' + FItems[i];
end;

// =============================================================================
procedure TSQL.Clear;
begin
  SetLength(FItems, 0);
end;

// =============================================================================
function TSQL.GetItem(index: integer): string;
begin
  Result := FItems[index];
end;

// =============================================================================
procedure TSQL.SetItem(index: integer; const Value: string);
begin
  FItems[index] := Value;
end;

// =============================================================================
function TSQL.IndexOf(const s: string): integer;
var
  k: integer;
begin
  Result := -1;
  for k  := 0 to Count - 1 do
  begin
    if FItems[k] = s then
    begin
      Result := k;
      break;
    end;
  end;
end;

 

Link to comment
Share on other sites

I determined that it worked if I used HTTP but not HTTPS.

 

BUT after not getting it to work, I made a small test program to show to Delphi Developer.  In the test program I changed it from <embed> to <iframe> like he said and it worked.

 

So he gave me the answer all along and I didn't try it because I could get it to work on my computer.

 

Once again Delphi Developer came through with the answer.  Just trust him.

  • Like 1
Link to comment
Share on other sites

  • 1 year later...

Please sign in to comment

You will be able to leave a comment after signing in



Sign In Now
×
×
  • Create New...