Zburatoru's Software Development Archive

Development insights..and more…

How to Create a Media Player in Silverlight

Posted on | July 20, 2011 | No Comments

Introduction to Multimedia in Silverlight

In this article we will learn about handling and implementing multimedia in a Silverlight application. Source code for creating a simple media player in Silverlight application is provided and explained. With this basic idea you could very well create a complete implementation of a fully sophisticated media player.

For this demonstration I have used Silverlight 4.0 and Visual Studio 2010.

Multimedia Support in Silverlight

Until the introduction of Silverlight there was no prominent Microsoft technology which could handle multimedia files. But with Silverlight a wide range of multimedia support is available which includes video files, audio files and photos.

MediaElement Silverlight Control

In Silverlight the multimedia files can be handled using the MediaElement control. All the developer needs to do is simply drag drop the UI element onto the XAML page and set a few basic properties which enables the media files to be played.

Notable Properties of MediaElement

Below are some of the important properties of the MediaElement control:

Source

This is the first and foremost property which is used to provide the path of the multimedia file which needs to be played.

AutoPlay

This is a Boolean property. When set to True the media file gets played as soon as the MediaElement control is loaded; if the value is set to false then the media file is not played by default.

IsMuted

This is a Boolean property used to specify whether the Media sound should be muted or not.

CacheMode

This property is used to specify whether the media file being played has to be cached or not.

BufferingTime

This is a property used to get or set the buffering time of the media file to be played. So playing the media file would wait until the set time is elapsed.

Notable Events of MediaElement

Below are some of the important MediaElement events that could be very useful which creating a MediaPlayer control in the Silverlight application.

MediaOpened

This event gets fired when the media source of the MediaElement gets opened.

MediaClosed

This event gets fired when the media gets closed after playing is complete. This event can be used to implement resetting the MediaElement’s state or to play the next video.

MediaFailed

Any special handling which needs to occur when the media element fails to play the content can be implemented using this event.

CurrentStateChanged

This event gets fired when the current state of the event is changed. For example when the state of the media element is changed from Play to Pause or Stop.

Sample Silverlight Multimedia Application Code

In this section we will create a sample application named SampleMediaPlayer in Silverlight and implement a Simple Media Player.

First, create a Silverlight application and name it as SampleMediaPlayer. Add a sample video file to the Silverlight application. After adding the sample video to the project, right click on the video file and click on properties. The window shown in Fig 1.0 will popup.

Image 1

Fig 1.0

Select the Build Action as Resource.

Now define the XAML code for the Media player. Below is the code:

xmlns=”http://schemas.microsoft.com/winfx/2006/xaml/presentation”

xmlns:x=”http://schemas.microsoft.com/winfx/2006/xaml”

xmlns:d=”http://schemas.microsoft.com/expression/blend/2008″

xmlns:mc=”http://schemas.openxmlformats.org/markup-compatibility/2006″

mc:Ignorable=”d” d:DesignHeight=”350″ d:DesignWidth=”500″>

Now let’s go ahead and implement the codebehind for the media player:

namespace SimpleMediaPlayer

{

public partial class MainPage : UserControl

{

public MainPage()

{

InitializeComponent();

SampleMediaElement.MediaOpened += new RoutedEventHandler(SampleMediaElement_MediaOpened);

SampleMediaElement.MediaEnded += new RoutedEventHandler(SampleMediaElement_MediaEnded);

SampleMediaElement.MediaFailed += new EventHandler(SampleMediaElement_MediaFailed);

SampleMediaElement.CurrentStateChanged += new RoutedEventHandler(SampleMediaElement_CurrentStateChanged);

}

void SampleMediaElement_MediaOpened(object sender, RoutedEventArgs e)

{

//Gets fired when the media file gets opened in the MediaElement

}

void SampleMediaElement_MediaFailed(object sender, ExceptionRoutedEventArgs e)

{

//Perform the failure handling

}

void SampleMediaElement_MediaEnded(object sender, RoutedEventArgs e)

{

//Implement the code to hadle the scenario when the media playing has ended

}

void SampleMediaElement_CurrentStateChanged(object sender, RoutedEventArgs e)

{

//Implement anything specific when the current media element state has changed

}

private void PlayPauseButton_Click(object sender, RoutedEventArgs e)

{

if (SampleMediaElement.CurrentState == MediaElementState.Paused || SampleMediaElement.CurrentState == MediaElementState.Stopped ||

SampleMediaElement.CurrentState == MediaElementState.Closed)

{

SampleMediaElement.Play();

PlayPauseButton.Content = "Pause";

}

else if(SampleMediaElement.CurrentState == MediaElementState.Playing)

{

SampleMediaElement.Pause();

PlayPauseButton.Content = "Play";

}

}

private void StopButton_Click(object sender, RoutedEventArgs e)

{

if (SampleMediaElement.CurrentState == MediaElementState.Paused || SampleMediaElement.CurrentState == MediaElementState.Playing)

{

SampleMediaElement.Stop();

PlayPauseButton.Content = "Play";

}

}

private void MuteButton_Click(object sender, RoutedEventArgs e)

{

if (SampleMediaElement.IsMuted)

{

SampleMediaElement.IsMuted = false;

MuteButton.Content = "Mute";

}

else

{

SampleMediaElement.IsMuted = true;

MuteButton.Content = "UnMute";

}

}

}

}

The MediaElement exposes the methods Play, Pause and Stop which can be called from the codebehind which gives good control over the media for the developer.

Image 2

Fig 1.1

Run the application and see the basic media player working. Fig 1.1 shows a sample screenshot.

Conclusion

Thus Silverlight provides a good support for multimedia. Through this article I hope you have learned about the MediaElement control and how to build a simple media player using it. Please make use of the comments section below to provide your feedback.

Happy reading!

Azure Toolkits Coming for Mobile Devices

Posted on | July 20, 2011 | No Comments

Microsoft may be desperate to succeed in the mobile marketplace with Windows Phone 7 (WP7), but that isn’t keeping the company from coming out with development tools to help iPhone and Android developers write apps that work with its Windows Azure cloud computing platform.

In a move meant to assure higher adoption of Azure, this week, Microsoft (NASDAQ: MSFT) announced Azure Toolkits for Devices — for Apple’s (NASDAQ: AAPL) iOS and Google’s (NASDAQ: GOOG) Android — as well as a coming update for the WP7 toolkit the company released last month.

“Using the toolkits, developers can use the cloud to accelerate the creation of applications on the major mobile platforms,” Jamin Spitzer, senior director of platform strategy at Microsoft, said in a post to the Official Microsoft Blog.

The toolkits use Azure’s cloud services as a common back-end. All three toolkits also come with a “cloud ready” deployment package, Microsoft said.

“Developers can use cloud services to share common requirements like device notifications, authentication, storage and even higher-level services like leaderboards,” the post added. “At the same time, developers can maximize the performance of each mobile device by writing client code that exploits each platform.”

To that end, Microsoft is readying an update to a toolkit it released last month for WP7 devices that takes advantage of Windows Azure. The pending update, which adds integration with Azure’s Access Control Service, provides support for Azure Storage Queues, and updates the user interface for the supporting Web application, is due out in the next two weeks.

The original WP7 toolkit, which shipped in late March, includes binaries for WP7 applications, project templates, sample applications written in C# and VB.NET, as well as a dependency checker.

Meanwhile, the Azure Toolkit for iOS provides compiled iPhone libraries for interacting with Azure, a sample iOS application, and documentation. The toolkit is currently available for download.

Additionally, not to leave any potentially large markets without the option, Microsoft said it is also working on an Azure Toolkit for Android, which it plans to ship this summer.

Microsoft launched Windows Azure in February 2010.

Understanding the SQL Azure Editions, Subscriptions Types and Pricing

Posted on | July 20, 2011 | 2 Comments

Introduction

SQL Azure is the cloud-based database service offered as part of Microsoft’s Windows Azure platform. SQL Azure offers a lot of business value to enterprises by way of its following features:

  • Scalability
  • Availability
  • Provisioning
  • Payment model
  • No-maintenance

The USP of SQL Azure lies in the fact that one does not have to worry about how much storage space they occupy on the server. “Large bursts” of data are no longer your IT department’s headache since the database is managed by Microsoft, including adding more storage capacity. Similarly, Microsoft datacenter folks ensure that your database is always available.

SQL Azure also offers high availability and failover support. Setting up multiple instances is a low–effort activity since no setup is required for provisioning your database.

With SQL Azure, you also have the option to pay as you consume, so if you are a consumer with meager requirements, you will end up paying less. As your consumption increases, your payments will also increase.

Also, SQL Azure allows an enterprise to focus on its business instead of infrastructure since the infrastructure is maintained by Microsoft. Microsoft is responsible for patching the machines, taking regular backup and other IT-centric activities.

Subscription Types

SQL Azure comes with two types of subscriptions. One is consumption-based and the other is commitment-based.

  1. Consumption based – In the consumption based subscription, you pay for what you use. The more you use, the more you pay. There is no time commitment involved.
  2. Commitment based – In a commitment-based subscription, you get the service at a discount but this requires a time commitment. Because of the time commitment involved, the pricing is discounted compared to the consumption-based model. However, you will have to pay even if you do not use the service.

SQL Azure Editions Explained

SQL Azure comes in two editions:

Web edition – This is targeted for web applications which need small data sets. The maximum database size supported is 5 GB with database size starting from 1 GB and pricing increments of 1GB.

Business Edition – This edition is best suited for line of business applications and enterprise applications. The database supported is 10GB to 50GB with pricing increments of 10GB.

Billing begins with creating of SQL Azure database.

Web edition is ideal for small web applications. Business edition, on the other hand, is targeted for more data-savvy enterprise applications like payroll processing or inventory management.

Pricing Meters

Pricing for SQL Azure is based on two factors: database size and data transfer.

Irrespective of the SQL Azure edition used, a monthly fee is charged for each SQL Azure database. Note that the Master database is not charged in either web edition or Business edition. The database fee is amortized over the month and is charged daily.

Let us explore this further. Consider a web edition database. The daily peak size for 4 days in a week is around 100MB but on Fridays and the weekend, it rises to over 3 GB.

The pricing for 1 GB (100 MB usage) is $9.99 per month, whereas for the rest of the week, it is priced at $49.99 per month (3GB daily use).

The net monthly price based on database size is calculated as under:

18/30 * 9.99 (18 days, we use only 100 MB daily) + 12 /30 * 49.99 (for 12 days, we use 3 GB daily)

This amounts to a net today of 25.99.

This means that monthly amortization has resulted in a customer paying only $25.99 per month instead of $49.99 which would have to be paid otherwise. This represents savings for the customer.

Data Transfer

No fees are charged for data transfer when data is transferred in the same data center. However if data is transferred between data centers or with an on-premise locations, the user is charged for data transfer based on gigabytes transferred.

Billing Information

Billing information is available at https://windows.azure.com (you might have to log in). You can view your monthly bill online. When you check the bill, you can also check the details of the data transfers which occurred in the billing cycle to understand your total bill (available athttps://mocp.microsoftonline.com)

Summary

In this article, we looked at the various SQL Azure editions, the available subscription types and the pricing for each subscription type.

Introduction to SQL Azure

Posted on | July 20, 2011 | No Comments

Introduction

Azure is Microsoft’s entry to the emerging competition in the cloud computing area. One of the services which is part of Azure is SQL Azure. SQL Azure is a cloud service which offers data processing and storage facilities. The SQL Azure platform is based upon SQL Server technology.

Selling Points for SQL Azure

  • By using cloud-based storage, businesses can reach new markets and customers by creating and offering SaaS (Software as a Service) applications. It allows enterprises to build web applications that can benefit from scale-out database capabilities.
  • Data consolidation – Having data in the cloud allows having a consolidated storage location avoid data segregation.
  • SQL Azure allows enterprise to focus on business instead of database management issues.
  • It allows enterprises to allow integrate data with analysis tools which build upon SQL server technologies which provide insight into business performance and processes.

Components of SQL Azure

SQL Azure is composed of the following components:

  • Database – The database is based upon SQL Server technologies, which means highly availability and scalable service with build-in fault tolerance.
  • SQL Azure Data Sync – SQL Azure includes a data synchronization services which can sync your data across cloud and on-premise sources. This is still in Community Technology Preview (as of writing this article). It allows bi-directional data synchronization.
  • SQL Azure Reporting – This component allows enterprises to use on-premise tools to develop and deploy reports. This is still in Community Technology Preview (as of writing this article). SQL Azure Reporting allows customers to access these reports from SQL Azure Management Portal or even from a business application. The top features of SQL Azure Reporting include Business Intelligence Design Studio and Report Builder.

Platform Tools

The following tools are supported to work with SQL Azure service.

Database Manager – An easy-to-use database management tool, it supports developing, deploying and managing your SQL Azure applications. It is available as part of the Windows Azure Platform Management Portal.

SQL Server Management Studio – SQL Server versions 2008 R2 and above come with SQL Server Management Studio which can directly connect to SQL Azure. Even the latest version of the free SQL Server Management Studio Express Edition will work with SQL Azure.

SQL Server migration Assistant – SQL Server Migration Assistant works with SQL Azure to migrate your data from Access, MySQL or Sybase formats.

SQL Server Integration Services – SSIS installations support importing and exporting data to SQL Azure.

BCP Utility – You can use the BCP utility for your bulk copy needs to/from SQL Azure to a user-specified format.

PowerPivot – You can use PowerPivot to do data analytics in Microsoft Excel against SQL Azure database.

Summary

In this article, we learned about the basic functionality provided by SQL Azure. I hope you have found the information useful.

 

Deploying your Azure application to the Cloud

Posted on | July 20, 2011 | No Comments

Introduction

In an earlier article, we saw how to create a simple Azure application. In this article, we will learn how to deploy our Azure application to the cloud, to make it a real cloud application.

ToolSet needed

In order to be able to deploy a Microsoft Windows Azure application, you will need:

Hands-On

If you have a project you created earlier following the “Creating a Simple Microsoft Windows Azure Application“, you can continue using that Visual Studio project to deploy.

If you do not have a project, you can download a pre-created solution here.

Open the “MyFirstAzureProject” in Visual Studio. Right click on MyFirstAzureProject and select Publish.

Figure 1

In the first phase, we will get the application packaged and ready for deployment. To do this, select “Create Service Package Only” and click “OK”.

Feature 2

Visual Studio will then proceed to create package. It should be created at the following path MyFirstAzureProject\bin\Debug\Publish.

You will notice two files in that folder.

Filename Purpose
MyFirstAzureProject.cspkg Package file for the Windows Azure application
ServiceConfiguration.cscfg Service configuration file for the Azure application

Deploying to the cloud

To deploy to the cloud, Login and if prompted, select to navigate to the new portal (There is a new Management portal deployed in January 2011). Select Hosted Services, Storage Account and CDN from the bottom left.

Figure 3

Click New Hosted Service in the top ribbon

Figure 4

In the popup window, fill in the details

Figure 5

Figure 6

For the package location, click browse locally and select the Deployment file created ago. Click OK to start validation of your service.

You might be greeted with a warning stating that you need more than one instance.

Figure 7

Go ahead and override the warning and click Yes.

You will see that the new Azure service has begun deploying to the cloud in the production environment.

Figure 8

After a minute, you can see that Deployment, Role and Instance are still “Initializing” and “Creating”. It can take up to 15 minutes for the application to be ready.

Figure 9

Once Deployment, Role and Instance display “Ready” status, your application is cloud ready.

Figure 11

At this time, you can navigate to the deployment node, and see the DNS name of your Azure application.

Figure 12

If you click on that URL, it will take you to your cloud application.

Figure 12

Summary

In this article, we saw how to deploy your Windows Azure application from your machine to the cloud. Hopefully, you have found the tutorial useful to you.

 

 

keep looking »