Sunday, 11 August 2013

Windows Phone - App for Getting the Audio Files List from Windows Phone along with Duration

  Now days mobility plays a key role in all aspects, In this article we are going to see a simple App which will get the Audio files present in Windows Phone along with Duration.

First Let we starts with an Design XAML , UI consists of a Listbox with an Data template,Which will show the Album name and Duration.

Steps to do :

  1. Launch the Visual studio 2010 and above 
  2. Select File, New Project
  3. Select the Create a windows Phone Application from Silverlight for Windows Phone.
  4. Give the name 
  5. Select Ok

XAML Code 

    mc:Ignorable="d" d:DesignWidth="480" d:DesignHeight="768"
    FontFamily="{StaticResource PhoneFontFamilyNormal}"
    FontSize="{StaticResource PhoneFontSizeNormal}"
    Foreground="{StaticResource PhoneForegroundBrush}"
    SupportedOrientations="Portrait" Orientation="Portrait"

    <!--LayoutRoot is the root grid where all page content is placed-->
    <Grid x:Name="LayoutRoot" Background="Transparent">
            <RowDefinition Height="Auto"/>
            <RowDefinition Height="*"/>

        <!--TitlePanel contains the name of the application and page title-->
        <StackPanel x:Name="TitlePanel" Grid.Row="0" Margin="12,17,0,28">
            <TextBlock x:Name="ApplicationTitle" HorizontalAlignment="Center" Text="Songs List" Style="{StaticResource PhoneTextNormalStyle}"/>           

        <!--ContentPanel - place additional content here-->
        <ListBox x:Name="ContentPanel" Grid.Row="1" Margin="12,0,12,0">
                    <StackPanel Orientation="Horizontal">
                        <TextBlock Text="{Binding Name}"></TextBlock>
                        <TextBlock Margin="2,2,2,2" Text="{Binding Duration}"></TextBlock>


C# Code:

    Right click the project and add reference the following  dll , which will get the details of media "Microsoft.Xna.Framework.Media". Iterate the Each and every item present in album.

using System;
using System.Collections.Generic;
using System.Linq;
using System.Net;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Animation;
using System.Windows.Shapes;
using Microsoft.Phone.Controls;
using System.IO.IsolatedStorage;
using Microsoft.Xna.Framework.Media;

namespace Songs_List
    public class Song
        public string Name { set; get; }
        public string Duration { set; get; }
    public partial class MainPage : PhoneApplicationPage
        // Constructor
        public MainPage()
            MediaLibrary libr = new MediaLibrary();
            List<Song> list = (from f in libr.Albums select new Song(){ Name=f.Name,Duration="      duration : "+f.Duration.ToString()}).ToList();
            ContentPanel.ItemsSource = list;

Design Installed App :

From the above image you can see the App is installed in the name of Songs_List in Windows Phone.

Output :

From the above image, You can see the Sample Music Album is present in Windows Phone , The Duration of that album is 00:01:17

From this article ,I hope you can learn some basic in Windows Phone Application.