Madmike's Blog

December 4, 2009

Another good thing developed by Microsoft

There was always a time when you needed to make an application that used videos and music ,and you needed to make a player from scratch , you needed to download lots of libraries and many dll for your project.
But now I’ve discovered an useful namespace made by Microsoft : Microsoft.Directx.AudioVideoPlayback.
These library is found in DirectX SDK and the latest version until now can be found here : Download here.

I will include some examples of how easy to use are this libraries:

Audio:

string filePath=”the location where is your file , including file name and extension”;
Audio audio=new Audio(filePath);

For the 3 state a music and movie could have : Play , Pause and Stop are made 3 methods
audio.Stop(), audio.Play() , audio.Pause() and also 3 states illustrated by 3 properties audio.Paused, audio.Stopped , audio.Playing (all 3 boolean).

Example of music player panel in C#:

public partial class MusicContainer : UserControl
{
public MusicContainer()
{
InitializeComponent();
}

public string Path { get; set; }
public Audio audio=null;
//control loaded and we try to load a movie from disk
private void MusicContainer_Load(object sender, EventArgs e)
{
if (audio == null)
{
audio = new Audio(Path);
label1.Text = Path;
}
//we use the timer to show music/movie progress
timer1.Start();
}
//button used for Play
private void button1_Click(object sender, EventArgs e)
{
if (audio != null)
{
if (audio.Paused || audio.Stopped)
{
audio.Play();
}
}
}
//button used to pause
private void button2_Click(object sender, EventArgs e)
{
if (audio != null)
{
if (audio.Paused)
{
audio.Pause();
}
}
}
//buton used for stopping
private void button3_Click(object sender, EventArgs e)
{
if (audio != null)
{
if (audio.Paused || audio.Playing)
{
audio.Stop();
}
}
}
//show the movie/music progress during playing every second
private void timer1_Tick(object sender, EventArgs e)
{
trackBar1.Value = (int)(audio.CurrentPosition / audio.Duration*100);
}
//navigate forward/backward in the movie/music
private void trackBar1_Scroll(object sender, EventArgs e)
{
audio.CurrentPosition = trackBar1.Value * audio.Duration / 100;
}
}

For the movie part is the same as music , but this one has more features.

Movie movie=new Movie(filePath);
Control control="a control that will be the video showing surface";
movie.Owner=control;
//or null if you want to take the full form of the container in which movie resides

movie.Fullscreen=true; // if you want to make it full screen

I found this namespace and used it , there are many examples of different players all over the MSDN and I was impressed of the quality of the playback and the useful and easiness to use it.

Have fun making your own player

September 26, 2009

How should you make a Currency Convertor?

Filed under: Asp.net,C#,Java,Programming,Webservice — Florescu Radu @ 13:11
Tags: , , ,

A smart guy made a very good web service that gives you all the values you need from the BNR (National Bank of Romania) , you can use it like I did.
Include e web service reference in your Visual Studio project , then you use a code like this to get all the info you need ,for your project.`
Link to your web service here
The code to get the currency is down here:
Curs c = new Curs();
double d=c.getlatestvalue(“eur”);
Console.WriteLine(d);

Have fun using it

September 6, 2009

How to integrate Dojo with ASP.net

Filed under: Asp.net,C#,Dojo,Programming — Florescu Radu @ 19:36
Tags: , , , ,

First steps

Start your visual studio 2008 (Start->Programs->Microsoft Visual Studio 2008->Microsoft Visual Studio 2008).And select Web Development Settings.Then click on Start visual Studio

Start a new Project (ASP.net Website)

<%@ Page AutoEventWireup=”true”  CodeFile=”Default.aspx.cs” Inherits=”_Default” %>

<!DOCTYPE html PUBLIC “-//W3C//DTD XHTML 1.0 Transitional//EN” “http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd”&gt;

<html xmlns=”http://www.w3.org/1999/xhtml”&gt;

<head runat=”server”>

<title>ASP.net and Dojo first example</title>

</head>

<body>

<form id=”form1″ runat=”server”>

<div>

</div>

</form>

</body>

</html>

Now lets include the code that will allow us to use the dojo scripts.This code ussually goes in the head part.

<script src=”Dojo/dojo/dojo.js”                       djConfig=”parseOnLoad:true”></script>

<script>

dojo.require(“dojo.parser”);

</script>

Now we have everything ready to unleash the power of Dojo

This is the first example of Dojo

<%@ Page AutoEventWireup=”true”  CodeFile=”Default.aspx.cs” Inherits=”_Default” %>

<!DOCTYPE html PUBLIC “-//W3C//DTD XHTML 1.0 Transitional//EN” “http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd”&gt;

<html xmlns=”http://www.w3.org/1999/xhtml”&gt;

<head runat=”server”>

<title>ASP.net and Dojo first example</title>

<script type=”text/javascript” src=”Dojo/dojo/dojo.js” djConfig=”parseOnLoad:true”></script>

<script type=”text/javascript”>

//include the necessary files to use dojo parser and the button we use in the //body

dojo.require(“dojo.parser”);

dojo.require(“dijit.form.Button”);

</script>

//include some themes from dojo by default

<style type=”text/css”>

@import “Dojo/dijit/themes/tundra/tundra.css”;

@import “Dojo/dojo/resources/dojo.css”;

</style>

</head>

<body>

// we make a form with name myForm and an input button to type something in //it

<form id=”myForm” runat=”server”  method=”get” action=”Default.aspx”>

Please enter your name:

<input type=”text”/>

<div>

//this is a dijit.form.button

//sure you observer one new attributes here like : dojoType and the name of //the control : button

<button dojoType=”dijit.form.Button”>

Hello World!

<script type=”dojo/method” event=”onClick”>

alert(“bla”);

</script>

</button>

</div>

</form>

</body>

</html>

This is the output

Dojo tutorials

Many of them are good ,but I used this ones and there were very good:

http://www.roseindia.net/dojo/

http://www.dojotoolkit.org/forum/dojo-foundation/general-discussion/step-step-dojo-tutorials

And some books like this ones: dojo-using-the-dojo-javascript-library-to-build-ajax-applications-developers-library and practical-dojo-projects-practical-projects.

Your can also learn by doing with dojo book version 1.3

Links and references

You can also use this tutorial to see the things from other perspective :

http://www.codeproject.com/KB/ajax/Dojo-AjaxDotNet.aspx

Blog at WordPress.com.