Giter Site home page Giter Site logo

syncfusionexamples / paly-sound-in-item-tap-listview-xamarin Goto Github PK

View Code? Open in Web Editor NEW
0.0 4.0 0.0 1.83 MB

This repository contains sample about how to make sound on tapping an item in Xamarin.Forms ListView (SfListView)

C# 100.00%
listview sflistview xamarin xamarin-forms audio-player tap-command

paly-sound-in-item-tap-listview-xamarin's Introduction

How to make sound on tapping an item in Xamarin.Forms ListView (SfListView)

Xamarin.Forms SfListView supports to use common API to load audio data from a shared location across UWP, iOS & Android with the help of SimpleAudioPlayer plugin.

You can also refer the following article.

https://www.syncfusion.com/kb/11687/how-to-make-sound-on-tapping-an-item-in-xamarin-forms-listview-sflistview

You can refer the following steps to achieve the requirement.

STEP 1: Install the Xam.Plugin.SimpleAudioPlayer Nuget package in the shared code project.

STEP 2: Place the audio file in the shared code project and set the Build action as follows,

Project Location Build action
Android Assets AndroidAsset
iOS Resources BundleResource
UWP Assets Content

You can also refer to the link below to use custom fonts in Xamarin.Forms. https://devblogs.microsoft.com/xamarin/adding-sound-xamarin-forms-app/

XAML

Bind the TapCommand of the SfListView.

<syncfusion:SfListView x:Name="listView" ItemSize="60" ItemsSource="{Binding ContactsInfo}" TapCommand="{Binding TappedCommand}">
    <syncfusion:SfListView.ItemTemplate >
        <DataTemplate>
            <Grid x:Name="grid">
                <Grid.ColumnDefinitions>
                    <ColumnDefinition Width="70" />
                    <ColumnDefinition Width="*" />
                </Grid.ColumnDefinitions>
                <Image Source="{Binding ContactImage}" VerticalOptions="Center" HorizontalOptions="Center" HeightRequest="50" WidthRequest="50"/>
                <Grid Grid.Column="1" RowSpacing="1" Padding="10,0,0,0" VerticalOptions="Center">
                    <Label LineBreakMode="NoWrap" TextColor="#474747" Text="{Binding ContactName}"/>
                    <Label Grid.Row="1" Grid.Column="0" TextColor="#474747" LineBreakMode="NoWrap" Text="{Binding ContactNumber}"/>
                </Grid>
            </Grid>
        </DataTemplate>
    </syncfusion:SfListView.ItemTemplate>
</syncfusion:SfListView>

C#

In the ViewModel class, loaded the audio file. Play the audio by calling Play method in the command execution method.

public class ContactsViewModel : INotifyPropertyChanged
{
    ISimpleAudioPlayer Player;
    public ObservableCollection<Contacts> ContactsInfo { get; set; }
    public Command TappedCommand { get; set; }

    public ContactsViewModel()
    {
        ContactsInfo = new ObservableCollection<Contacts>();
        TappedCommand = new Command(OnTapped);

        Player = CrossSimpleAudioPlayer.Current;
        Player.Load("TapSound.wav");

        GenerateInfo();
    }

    private void OnTapped()
    {
        Player.Play();
    }
}

paly-sound-in-item-tap-listview-xamarin's People

Contributors

jayaleshwari avatar syncfusionbuild avatar

Watchers

 avatar  avatar  avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.