How To Embed Any Media Player in GridView Control

by Kareem Allam 3. August 2011 06:01

This example shows how to use any media player in  GridView Control and Get movie file  path  (server Pathe or obtain videos from YouTube )  from MS SQL Database

 

MS SQL Database Table Structure

 

 

MS SQL Database Table Data

 

 

HTML Side

In your Page you Must insert in   GridView Control and SQL DataSource

 

<asp:SqlDataSource 
    ID="SqlDataSource1"
    runat="server"
    ConnectionString="<%$ ConnectionStrings:XConStr %>"
    SelectCommand="SELECT ID, Name, FilePath, Youtube FROM media">
</asp:SqlDataSource>

 

 

<asp:GridView
	ID="GridView1"
	runat="server"
	AutoGenerateColumns="False"
	DataKeyNames="ID"
	DataSourceID="SqlDataSource1" >

   <Columns>
 
     <asp:BoundField
	DataField="ID"
	HeaderText="ID"
	ReadOnly="True"
	SortExpression="ID" />
 
     <asp:BoundField
	DataField="Name"
	HeaderText="Name"
	SortExpression="Name" />
 
     <asp:BoundField
	DataField="FilePath"
	HeaderText="FilePath"
	SortExpression="FilePath" />
 
     <asp:CheckBoxField
	DataField="Youtube"
	HeaderText="Youtube"
	SortExpression="Youtube" />
 
  </Columns>
</asp:GridView>

 

 

THat Is the simply basic design for controls

NOW , I waill start to insert the Players

1 – Convert FilePath Field in GridView To Template Field

 

2 – Insert 2 Invisible Panels to template filed

       ( 1 For Media Palyer & The second for Youtube )

 

<asp:TemplateField HeaderText="FilePath" SortExpression="FilePath">
    <ItemTemplate>
        <asp:Panel ID="Panel_MediaPlayer" runat="server" Visible="false">
             <object width="200" height="200"
                  classid="CLSID:22d6f312-b0f6-11d0-94ab-0080c74c7e95"
                  id="MPPlayer">
             <param name="Filename" value='<%# Eval("Name") %>'>
             <param name="AutoStart" value="False">
             <param name="ShowControls" value="True">
             <param name="ShowStatusBar" value="True">
             <param name="ShowDisplay" value="False">
             <param name="AutoRewind" value="True">
                  <embed
                      type="application/x-mplayer2"
                      pluginspage="http://www.microsoft.com/Windows/Downloads/Contents/MediaPlayer/"
                      width="200" height="200" src='<%# Eval("FilePath") %>'
                      filename='<%# Eval("Name") %>' autostart="False"
                      showcontrols="True" showstatusbar="False"
                      showdisplay="False" autorewind="True">
                  </embed>
             </object>
        </asp:Panel>
                              

        <asp:Panel ID="Panel_Youtube" runat="server" Visible="false">
             <object width="200" height="200" >
             <param name='<%# Eval("Name") %>' value='<%# Eval("FilePath") %>' />
             <param name="allowFullScreen" value="true"/>
             <param name="allowscriptaccess" value="always"/>
                  <embed src='<%# Eval("FilePath") %>'
                      type="application/x-shockwave-flash"
                      allowscriptaccess="always"
                      allowfullscreen="true"
                      width="200" height="200"
                      pluginspage="http://www.adobe.com/go/getflashplayer">
                  </embed>
             </object>
        </asp:Panel>
                                
   </ItemTemplate>
</asp:TemplateField>

 


 

Code Side

 

Protected Sub GridView1_RowDataBound _
       (ByVal sender As Object, _
        ByVal e As System.Web.UI.WebControls.GridViewRowEventArgs) _
        Handles GridView1.RowDataBound
 
        Dim XPanel_MediaPlayer As New Panel
        Dim XCPanel_Youtube As New Panel
 
        If e.Row.RowType = DataControlRowType.DataRow Then
            XPanel_MediaPlayer = e.Row.FindControl("Panel_MediaPlayer")
            XCPanel_Youtube = e.Row.FindControl("Panel_Youtube")
 
            XPanel_MediaPlayer.Visible = False
            XCPanel_Youtube.Visible = False
 
            If Val(Convert.ToInt32(DataBinder.Eval(e.Row.DataItem, "Youtube"))) = 1 Then
                XCPanel_Youtube.Visible = True
            Else
                XPanel_MediaPlayer.Visible = True
            End If
 
        End If
 
    End Sub

 

 

 

 PS

You can Use any player , just insert the appropriate Object

 

Player 

File Formats 

Flash 

flv, mp3, swf

Windows Media Player 

asx, asf, avi, wma, wmv

QuickTime 

aif,aiff,aac,au,bmp,gsm,mov,mid,

midi,mpg,mpeg,mp4,m4a,psd,qt,qtif,

qif,qti,snd,tif,tiff,wav,3g2,3pg

Real Player 

ra, ram, rm, rpm, rv, smi, smil

 

 

 

Audio File

<object codebase="http://www.apple.com/qtactivex/qtplugin.cab" 
        classid="clsid:6BF52A52-394A-11d3-B153-00C04F79FAA6" 
        type="application/x-oleobject"> 
        <param name="url" value=" FileName.avi"> 
        <embed src="FileName.avi" 
            type="application/x-mplayer2" 
            pluginspage="http://www.microsoft.com/Windows/MediaPlayer/">
         </embed> 
</object>


 

 

QuickTime Movie

 

<object codebase="http://www.apple.com/qtactivex/qtplugin.cab" 
        classid="clsid:02BF25D5-8C17-4B23-BC80-D3488ABDDC6B"> 
        <param name="src" value=" FileName.mov"> 
        <embed src=" FileName.mov" 
            pluginspage="http://www.apple.com/quicktime/download/">
        </embed> 
</object>

 


Flash  Movie

<object codebase="http://fpdownload.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=7" 
        classid="clsid:d27cdb6e-ae6d-11cf-96b8-444553540000" 
        type="application/x-oleobject"> 
        <param name="src" value=" FileName.swf"> 
        <embed src=" FileName.swf" 
            type="application/x-shockwave-flash" 
            pluginspage="http://www.adobe.com/go/getflashplayer">
         </embed> 
</object>


If you enjoyed this post, make sure you subscribe to my RSS feed!

Collected Quotes about Failure

by Kareem Allam 2. August 2011 01:16


Failure is only a temporary change in direction to set you straight for your next success.

- Denis Waitley

Failures do what is tension relieving, while winners do what is goal achieving.

- Denis Waitley

Success is going from failure to failure without losing your enthusiasm.

- Abraham Lincoln

My great concern is not whether you have failed, but whether you are content with your failure.

- Abraham Lincoln

Success is often the result of taking a misstep in the right direction.

- Al Bernstein

Mistakes are a part of being human. Appreciate your mistakes for what they are: precious life lessons that can only be learned the hard way. Unless it's a fatal mistake, which, at least, others can learn from.

- Al Franken -

Anyone who has never made a mistake has never tried anything new.

- Albert Einstein

Women must try to do things as men have tried. When they fail their failure must be but a challenge to others.

- Amelia Earhart

Keep on beginning and failing. Each time you fail, start all over again, and you will grow stronger until you have accomplished a purpose - not the one you began with perhaps, but one you'll be glad to remember.

- Anne Sullivan

In order to succeed you must fail, so that you know what not to do the next time.

- Anthony J. D'Angelo

One must be a god to be able to tell successes from failures without making a mistake. 

- Anton Pavlovich Chekhov

A failure is not always a mistake, it may simply be the best one can do under the circumstances. The real mistake is to stop trying.

- B. F. Skinner

Through perseverance many people win success out of what seemed destined to be certain failure.

- Benjamin Disraeli

All my successes have been built on my failures.

- Benjamin Disraeli

Do not fear mistakes. You will know failure. Continue to reach out.

- Benjamin Franklin

In order to succeed, your desire for success should be greater than your fear of failure.

- Bill Cosby

I don't know the key to success, but the key to failure is trying to please everybody.

- Bill Cosby

Once you start a working on something, don't be afraid of failure and don't abandon it. People who work sincerely are the happiest.

- Chanakya

An inventor fails 999 times, and if he succeeds once, he's in. He treats his failures simply as practice shots.

- Charles F. Kettering

Failure sometimes enlarges the spirit.  You have to fall back upon humanity and God. 

- Charles Horton Cooley

Success is often achieved by those who don't know that failure is inevitable.

- Coco Chanel

There are no secrets to success. It is the result of preparation, hard work, and learning from failure.

- Colin Powell

It's fine to celebrate success but it is more important to heed the lessons of failure.

- Bill Gates

It’s how you deal with failure that determines how you achieve success.

- David Feherty

 

Our greatest glory is not in never failing, but in rising every time we fail.

- Confucius

A failure establishes only this, that our determination to succeed was not strong enough.

- Christian Nestell Bovee

Develop success from failures. Discouragement and failure are two of the surest stepping stones to success.

- Dale Carnegie

Losers live in the past. Winners learn from the past and enjoy working in the present toward the future.

- Denis Waitley

Forget about the consequences of failure. Failure is only a temporary change in direction to set you straight for your next success.

- Denis Waitley

Failure should be our teacher, not our undertaker. Failure is delay, not defeat. It is a temporary detour, not a dead end. Failure is something we can avoid only by saying nothing, doing nothing, and being nothing.

- Denis Waitley

It is a mistake to suppose that people succeed through success; they often succeed through failures. 

- Author Unknown

The things that hurt us teach us.

- Author Unknown

Failure is only the opportunity to begin again, this time more wisely.

- Author Unknown

You're on the road to success when you realize that failure is only a detour.

- Author unknown

It is wise to keep in mind that no success or failure is necessarily final. 

- Author Unknown

 

 

 

If you enjoyed this post, make sure you subscribe to my RSS feed!

Set HTML Attributes for Controls in ASP.NET

by Kareem Allam 2. August 2011 01:00

You can set HTML Attributes for any ASP.Net Controls and use it in code to use control value

 

Set HTML Attributes for Any Controls 

HTML Side 

<body id="body" runat="server">
    <form id="form1" runat="server">
       <input runat="server" id="Button1" type="button"/>
    </form>
</body>

 

 

 

Code Side (vb.net)

   

Private Sub Page_Load(ByVal sender As System.Object, _
                     ByVal e As System.EventArgs) Handles MyBase.Load
 
        Button1.Attributes.Add("onclick", "alert('Message')")
        body.Attributes("bgcolor") = "black"

 
    End Sub

 

If you enjoyed this post, make sure you subscribe to my RSS feed!

About EgDev.com

If you would like to find value services with excellent quality and cost effectiveness and with a focus on speed , Just Follow

 Egypt Development Freelance Team.

Month List

Page List