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!

Comments (32) -

bucino ulje
bucino ulje United States
8/8/2011 5:04:51 PM #

Hi there, just became aware of your blog through Google, and found that it is truly informative. I’m going to watch out for brussels. I will be grateful if you continue this in future. Lots of people will be benefited from your writing. Cheers!

Website Designing
Website Designing United States
9/17/2011 7:51:41 AM #

Hi, for some reason when I place your feed into google reader, it won?t work. Can you give me the RSS link just to be sure I?m using the most appropriate one?

Kareem Allam
Kareem Allam Egypt
9/18/2011 9:36:24 AM #

http://feeds.feedburner.com/EgyptDevelopmentBlog
that RSS Feed Link worked with me normally in google reader
try it then feed me back if you have any problem
thank you for visiting my blog

judgement on credit report
judgement on credit report United States
9/22/2011 2:21:19 AM #

This is the nice web site. Good fresh interface and nice informative articles. We are re-occurring soon,wanted great article.

Kareem Allam
Kareem Allam Egypt
9/22/2011 1:58:18 PM #

thank you for comment ,,, I hope my post be useful to you

how to build links
how to build links
9/24/2011 11:57:44 AM #

I actually like your post.  It’s evident which you have a whole lot knowledge on this topic.  Your points are well created and relatable.  Thanks for writing engaging and intriguing material.
Discovered this on Bing and I’m pleased I did

Web Design Sheffield
Web Design Sheffield United Kingdom
9/24/2011 1:37:21 PM #

This is an excellent post. I really appreciate with you. I enjoyed the post. Thanks for sharing.

Carmelina Almasi
Carmelina Almasi United States
9/24/2011 11:43:08 PM #

Thank you for an intriguing and thought provoking article.

Roman Mccrory
Roman Mccrory United States
9/26/2011 6:15:16 PM #

Applause for this post - one of your best!

Future Web Design
Future Web Design
9/27/2011 11:32:23 AM #

Thanks  for the share

Future Web Design
Future Web Design
9/27/2011 11:36:03 AM #

Thanks  for the share

Ballerina flats
Ballerina flats United States
9/28/2011 3:59:22 AM #

This is amazing reporting... this is what keeps folks coming back

jenna
jenna
9/29/2011 8:11:18 AM #

Hi..

I am happy your own post was on the market for reading. It’s very thought-provoking, informative, bold, primary and creative.

This information has given me the brand new perspective along this particular topic. Thank you..

Nice blog tooo  ;)

letter holder
letter holder United States
10/1/2011 1:04:25 AM #

Hello! This is a real good site.

alliance one collections
alliance one collections United States
10/7/2011 12:15:49 AM #

I like your post, thanks for your information.

Barbara B.
Barbara B.
10/8/2011 12:30:20 PM #

Thank for amazing article! I really enjoyed reading it.  I will make certain to bookmark your weblog and will definitely come back later on.  Carry on fantastic work. Have a great day.

buy vigrx
buy vigrx United States
10/16/2011 5:03:57 AM #

great post.. i really enjoyed it

Fred
Fred United States
10/17/2011 7:30:13 PM #

Merci pour ce post.

Deepak
Deepak India
10/20/2011 10:32:23 AM #

Thos blogs must have been interesting!

Windows Hosting M6.Net
Windows Hosting M6.Net United States
10/20/2011 7:08:58 PM #

Great to guide us with coding. Very useful. Thanks. Ahsima

Robert
Robert
10/22/2011 4:39:50 PM #

Hi

Nice, post here may come back soon

payer sur internet
payer sur internet France
11/6/2011 10:57:46 PM #

Ok pour ce que je viens de lire mais ca manque quand même de précisions, non ?

Guide Marrakech
Guide Marrakech France
11/7/2011 10:25:43 AM #

Truly stimulating info !Utopian true what I was searching for!

Web Design Manchester
Web Design Manchester United Kingdom
11/12/2011 6:27:02 PM #

Is there an RSS feed for this?

Rehoboth
Rehoboth United States
11/19/2011 6:30:48 PM #

Thank you for this interesting article. I have book marked this site because I really hope you write more articles soon, I plan to share this.

cheap web hosting
cheap web hosting
12/10/2011 1:04:33 PM #

Thanks  for the awesome share.
Great blog you have here.

ipage hosting
ipage hosting
12/10/2011 1:08:20 PM #

Thanks  for the amazing share.
Great blog you have here.

Hebergement Web
Hebergement Web
12/18/2011 12:09:37 AM #

hello there,

Interresting post here may come back soon
continue updating your blog

sjr group
sjr group Indonesia
12/22/2011 8:32:09 AM #

nice post........shared..

forexrobot.eu.com
forexrobot.eu.com United Kingdom
12/24/2011 4:35:37 PM #

nice article thanks for sharing this with us.

john
john United States
1/10/2012 6:12:35 PM #

great site.. nice article

Hermes Bags
Hermes Bags United States
6/29/2012 10:50:52 AM #

this is great post, thanks for share,

Pingbacks and trackbacks (1)+

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