play mp3 song using asp.net - c#

I am developing an online listen music website, on that I want to play song based on the user selection from gridview.right now I am using flash object for playing mp3 and video file this is running fine but its static path.how I can dynamically pass file URL of selected song on flash object.
waiting for your reply.

Using flashvars (requires reloading the page/SWF)
The easiest way would be to pass in the URL as a flashvar, e.g. via the querystring of the SWF file in your object/embed tag:
MyPlayer.swf?url=/path/to/song.mp3
The /path/to/song.mp3 can of course be printed by some server-side logic.
In Flash, you can then access the value of this variable using the LoaderInfo instance of the root:
var url : String = root.loaderInfo.parameters['url'];
If you want to provide a default for when no flashvar is specified, which is great for dev purposes especially, you can do this by using the || operator.
var url : String = root.loaderInfo.parameters['url'] || 'default.mp3';
This will use the specified URL if such exists, or else fall back to use default.mp3.
Using ExternalInterface & Javascript
If you don't want to reload the page, set up a javascript interface to your Flash player using ExternalInterface, e.g. like so:
if (ExternalInterface.available) {
ExternalInterface.addCallback('playUrl', playUrl);
}
function playUrl(url : String) : void {
// TODO: Add playback code here, e.g. using new Sound(url);
}
Then, from Javascript, you can do this:
var swf = document.getElementById('idOfSwfEmbed');
swf.playUrl('http://example.com/path/to/song.mp3');
This will invoke the ActionScript method playUrl() using the javascript API that was set up by ExternalInterface.addCallback().
I don't know .NET, so you'll need to figure out yourself how to invoke the playUrl() javascript method when a song is selected in your GridView.

If you use the <object /> tag to add the *.swf to the page:
Add following to the tag:
<object ...>
<param name="flashvars" value="path=<%# YOUR_PATH; %>">
</object>
And then inside the SWF:
var path:String = root.loaderInfo.parameters.path;

Hello friends i have got the answer for dynamically play the song.here is my code for this.
protected void GridView1_RowCommand(object sender, GridViewCommandEventArgs e)
{
if (e.CommandName.Equals("Play Now"))
{
int index = Convert.ToInt32(e.CommandArgument);
GridViewRow row = gridCalls.Rows[index];
string songname = row.Cells[5].Text; // second column in the sql server database
StringBuilder str = new StringBuilder();
str.Append("<object width='300px' height='300px'>");
str.Append("<param name='autostart' value='true'>");
str.Append("<param name='src' value='songs/" + songname + "'>");
str.Append("<param name='autoplay' value='true'>");
str.Append("<param name='controller' value='true'>");
str.Append("<embed width='300px' height='300px' src='songs/" + songname + "' controller='true' autoplay='true' autostart='True' type='audio/wav' />");
str.Append("</object>");
LoadPlayer.Text = str.ToString();//here loadplayer is label control
}
}

Related

How to use the ImageUrl property?

I want to show products using TileView, but I do not show pictures when I give url. How can I overcome this problem?
private void tileView1_ItemCustomize(object sender, DevExpress.XtraGrid.Views.Tile.TileViewItemCustomizeEventArgs e)
{
TileView view = sender as TileView;
string ID = view.GetRowCellValue(e.RowHandle, "ID").ToString();.ToString();
string url = "http://webpage.com/images/"+ ID + ".jpg";
e.Item.Elements[6].ImageUri = url;
}
The simple answer to using URI is this:
e.Item.Elements[6].ImageUri = new Uri(url);
The problem in your case might be that the image must first be downloaded in order for the control to use it. So you're probably going to have to do something like this first:
https://stackoverflow.com/a/3615831/1633308
and then, instead of your URI being the web address, it would be the local image file (probably in temporary storage that you clean up later).

How to dynamically generate and send jQuery to the webpage from C# AND have it work

So, I am dynamically generating jQuery using C# and sending it to the webpage.
The problem is it appears to be generating correct jQuery according to the file and according to Js Fiddle but it does not actually work on the page.
The jsFiddle is here http://jsfiddle.net/ER2hE/
Now I looked up how to send javacript to the website. It should work like this.
http://msdn.microsoft.com/en-us/library/bb359558.aspx
and my code which does that is this method
private void sendScript(string script)
{
const string someScript = "alertMe";
//send the built script to the website.
ScriptManager.RegisterStartupScript(this.Page, this.GetType(), someScript, script, true);
}
This is super simple it has worked for other pieces of code calling. But it has not for this instance.
The code that calls it is this in my C#
private void populateGroups()
{
//this generates correct javascript according to the file and JS fiddle but unfortunately doees not work.
string splitme = "USE ACES SELECT GroupName, GroupID FROM PrimaryGroup ORDER BY GroupName";
DataTable dt = fillDataTable(splitme);
string script = "";
foreach (DataRow dr in dt.Rows)
{
//add the locations to the <select> box
script += " $('#groupList').append('<option value=\" " + dr.ItemArray[1].ToString() + " \"> " + dr.ItemArray[0].ToString() + " </option>'); ";
}
sendScript(script);
JSErrorLog(script, "GROUPS");
}
The whole thing is being called on startup
protected void Page_Load(object sender, EventArgs e)
{
if (this.IsPostBack == false)
{
populateMakes();
populateLocation();
populateGroups();
}
}
The jQuery its generating also works in JSFiddle I am pulling this from a method that writes the javascript it generates in a method calling here is the fiddle JSErrorLog.
http://jsfiddle.net/ER2hE/
Oh and my html in my aspx file looks like this
<div class="row2">
<span>Group</span>
<select id="groupList" multiple="multiple" onclick="setGroups()" class="normalsize">
</select>
</div>
I believe that is everything. I just want my stuff to work. I am willing to post any additional code, just ask. If you have an idea as to why its not working, let me know.
When does it actually execute that code? Before or after the element with id "groupList" exists in the DOM? My guess is before.
Solution? Wrap your code inside a document.ready handler.
jQuery(function($) {
$('#groupList').append('<option value=" 46 "> AC Units </option>');
// etc etc
});
Return simple string js code. And run it with eval()

C# Project Google map

For my studying and university I have a project where I need to make an application using C# WPF. This application must allow me to select a path between two adresses and show the path on the map like google map.
How can I implement the google webservice API ? I am a bit lost with it and I don't understand how I can make my application and fit in the google map itself.
With this i must be able to calculate the distance as well.
This is what i have done with the webBrowser but it displays the whole website of google maps:
I know that the WebBrowser control can display the google maps but it doesnt actually work
This is my code actually
private void btnCharger_Click(object sender, RoutedEventArgs e)
{
//Use static or WebControl we don't know yet.
//This is the case we use webControl
string street = "";
string city = "";
string zipcode = "";
StringBuilder adresseQuery = new StringBuilder();
adresseQuery.Append("http://maps.google.com/maps?q=");
street = tbStreet.Text.Replace(" ", "+");
adresseQuery.Append(street + ",+");
city = tbCity.Text;
adresseQuery.Append(city + ",+");
zipcode = tbZipCode.Text;
webBrowser1.Navigate(adresseQuery.ToString());*/
}
So in this code i have created the adresse and sent it to the webbrowser through google maps. But is shows the whole google map page with the left bar and everything. I would like to only display the map ! How can i only display the map and not the bars present on the https://maps.google.com/
I have already checked this Link and am currently working on it but this is static.
For the part of routing/getting the directions (and for some of others functions you need as well), you can use a .NET wrapper around Google Maps API:
GoogleApi
google-maps
gmaps-api-net is outdated (at this time of answering) - the last update for the Directions API was made in 2016.
Usage example for GoogleApi:
using GoogleApi.Entities.Common;
using GoogleApi.Entities.Maps.Directions.Request;
using GoogleApi.Entities.Maps.Directions.Response;
public void GetRoute()
{
DirectionsRequest request = new DirectionsRequest();
request.Key = "AIzaSyAJgBs8LYok3rt15rZUg4aUxYIAYyFzNcw";
request.Origin = new Location("Brasov");
request.Destination = new Location("Merghindeal");
var response = GoogleApi.GoogleMaps.Directions.Query(request);
Console.WriteLine(response.Routes.First().Legs.First().DurationInTraffic);
Console.WriteLine(response.Routes.First().Legs.First().Distance);
Console.WriteLine(response.Routes.First().Legs.First().Steps);
}

How to read something from a file with C# and use it with HTML codes on ASP.NET page?

I'm doing a school project, I need to make a simple web site, add google maps on it, read, lets say, 100 diffrent addresses from a text file and show those locations on google maps with markers.
Now I'm trying to add google maps to my ASP.net page with javascript which I saw on google maps tutorials. And there's that problem which I have to convert adresses to coordinates. So for that I'm using
function addAddressToMap(response) {
if (!response || response.Status.code != 200) {
alert("Sorry, we were unable to geocode that address");
}
else {
place = response.Placemark[0];
point = new GLatLng(place.Point.coordinates[1],place.Point.coordinates[0]);
marker = new GMarker(point);
map.addOverlay(marker);
marker.openInfoWindowHtml(place.address + '<br>' + '<b>Country code:</b> ' + place.AddressDetails.Country.CountryNameCode);
}
}
// showLocation() is called when you click on the Search button
// in the form. It geocodes the address entered into the form
// and adds a marker to the map at that location.
function showLocation() {
var address = "izmit";
var address2 = "ağrı";
geocoder.getLocations(address, addAddressToMap);
geocoder.getLocations(address2, addAddressToMap);
}
these functions and they are working fine. But my problem here is, I need to get these address informations from a text file. But to get them, I need to use a few diffrent codes. And I want to make it on the server side with C# codes. But I don't know how to write some codes on server side and then return something to HTML side as address. I hope you understand. Thank you for your helps.
Update:
Server code:
public partial class _Default : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
Page.ClientScript.RegisterArrayDeclaration("Skills", "'asa'");
Page.ClientScript.RegisterArrayDeclaration("Skills", "'bell'");
Page.ClientScript.RegisterArrayDeclaration("Skills", "'C'");
Page.ClientScript.RegisterArrayDeclaration("Skills", "'C++'");
}
}
Client side:
function showLocation()
{
var address = "izmit";
var address2 = "ağrı";
geocoder.getLocations(Skills[0], addAddressToMap);
}
Now if I use "asa" instead of Skills[0] it will show the location and mark, but with Skills[0] it's not working. And thank you for your answer that was what I'm looking for.
even if I try var MyValue = Skills[0]; and then use MyValue instead of Skills[0] it's still not working
If I understood your question correctly, you want to create an array on the server side and read it in the client.
See this link for a tutorial on how to pass an array from the server to the client.
Basically, you want to use the ClientScriptManager.RegisterArrayDeclaration method to add values to the array.
You can then easily read it in javascript.
Server Side:
string arrayName = "MyArray";
Page.ClientScript.RegisterArrayDeclaration(arrayName , "'value1'");
Page.ClientScript.RegisterArrayDeclaration(arrayName , "'value2'");
Javascript on Client Side:
function readArray()
{
for (var i = 0; i < MyArray.length; i++)
{
//Reading Element From Array
var myValue = MyArray[i];
}
}

Using Webclient to POST/select all the option Values of a Multiselect

I am trying to write an application to automate router configuration. Unfortunately with the router we are using, telnet is not an option.
So I have had to interface with the Cisco web interface using C# WebClient class.
Up until now I had been able to set everything I needed using NameValueCollection and WebClient.UploadValues.
I would take all the input elements on the form, then just upload the name value Collection corresponding to the input types on the form, setting the values of each to the desired setting.
But now I have run into a problem.
With one of the forms, it is using a multiselect control to handle an array of input data, not an input type.
I am at a total loss for how to set this.
The html for the multiselect is as follows
<select multiple class="MultiSelect" name="PortRangeList" size="12" onChange="showList(this.form.PortRangeList);" style="width: 100%">
<option value="All Traffic{[(*-*-*)]}1;0;1;65535;0}">All Traffic [TCP&UDP/1~65535]</option>
<option value="DNS{[(*-*-*)]}2;17;53;53;0}">DNS [UDP/53~53]</option>
<option value="FTP{[(*-*-*)]}3;6;21;21;0}">FTP [TCP/21~21]</option>
...
</select>
When I was using the input types, I would simply do the following
NameValueCollection formNetworkData = new NameValueCollection();
formNetworkData["ipAddr"] = "192.168.1.2";
formNetworkData["lanMask"] = "255.255.255.0";
downloadedData = _routerWebClient.UploadValues(_routerIP + NETWORK, formNetworkData);
But looking at the code for this new form, it appears right before it submits, it selects all the options in the multiselect.
I realize I have probably asked this question poorely, but any assistance would be greatly appreciated.
Using Chrome debugger PortRangeList is exactly as you said.
There are 5 input types
submitStatus, upnpOpen (etc...)
For those my code looks like this
NameValueCollection formData = new NameValueCollection();
formData["submitStatus"]="1";
formData["upnpOpen"]="0";
downloadedData = _routerWebClient.UploadValues(SERVICE0, formData);
But in order to submit the PortRangeList data, I can't use the NameValueCollection because it does not allow a name to have muliple values.
how could submit that?
WebClient.UploadData, WebClient.UploadFile or WebClient.UploadString maybe?
Use Fiddler or Wireshark to compare what goes over the wire when it works ("normal" browser) and when it doesn't work (your code)... once you know the differences you can change your code accordingly...
You have to pass in the selected options by passing in the "PortRangeList" parameter multiple times, once for each option:
PortRangeList=All Traffic{[(*-*-*)]}1;0;1;65535;0}&PortRangeList=DNS{[(*-*-*)]}2;17;53;53;0}&PortRangeList=FTP{[(*-*-*)]}3;6;21;21;0}
That's how browsers do it. Since you're using the WebClient, try this:
PortRangeList=All Traffic{[(*-*-*)]}1;0;1;65535;0},DNS{[(*-*-*)]}2;17;53;53;0},FTP{[(*-*-*)]}3;6;21;21;0}
Obviously, everything has to be properly URL-escaped.
Thought I would post the final answer.
In the end I used the exact solution shown here.
http://anhonga.wordpress.com/2010/05/06/using-webclient-with-uploadvalues-and-uploadstring-to-simulate-post/
This is with his code, but I did essentially the exact same thing (without using global variables)
StringBuilder _strBld = new StringBuilder();
int _intItemCount = 0;
protected void btnSubmit_Click(object sender, EventArgs e)
{
System.Net.WebClient myWebClient = new System.Net.WebClient();
myWebClient.Headers.Add("Charset", "text/html; charset=UTF-8");
myWebClient.Headers.Add("Content-Type", "application/x-www-form-urlencoded"); // ◄ This line is essential
// Perform server-side validations (same as before)
if (this.F_Name.Text.Length == 0 || this.L_Name.Text.Length == 0)
{ AppendError("First and Last name must be provided"); }
…
// Add the user-provided name values
AppendUploadString("last_name", this.L_Name.Text);
AppendUploadString ("first_name", this.F_Name.Text);
AppendUploadString ("address", this.Address.Text);
// Add the Toppings
foreach (ListItem item in this.ToppingsChkBoxList.Items)
{
if (item.Selected)
{
AppendUploadString("Toppings", item.Value.ToString());
}
}
myWebClient.UploadString("https http://www.Destination.com/...?encoding=UTF-8", "POST", _strBld.ToString());
}
private void AppendUploadString(string strName, string strValue)
{
_intItemCount++;
_strBld.Append((intItemCount == 1 ? "" : "&") + strName + "=" + System.Web.HttpUtility.UrlEncode(strValue));
// Update: Use UrlEncode to ensure that the special characters are included in the submission
}

Categories

Resources