mainpage.xaml
- <UserControl x:Class="musicPlayer.MainPage"
- 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:DesignWidth="640" d:DesignHeight="480">
- <Grid x:Name="LayoutRoot" ShowGridLines="True" Background="Black">
- <MediaElement x:Name="media" Source="HUMAN_TOUCH.mp3" AutoPlay="False"/>
- <StackPanel VerticalAlignment="Stretch">
- <Button Content="Play" x:Name="play" Click="play_Click" Margin="5" />
- <Button Content="Pause" x:Name="pause" Click="pause_Click" Margin="5" />
- <Button Content="Stop" x:Name="stop" Click="stop_Click" Margin="5" />
- <Button Content="Mute" x:Name="mute" Click="mute_Click" Margin="5" />
- <Slider Grid.Row="1" x:Name="vol" Minimum="0" Maximum="1" ValueChanged="vol_ValueChanged" Margin="5" />
- </StackPanel>
- </Grid>
- </UserControl>
mainpage.xaml.cs
- 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;
- namespace musicPlayer
- {
- public partial class MainPage : UserControl
- {
- public MainPage()
- {
- InitializeComponent();
- vol.Value = media.Volume;
- }
- private void play_Click(object sender, RoutedEventArgs e)
- {
- media.Play();
- }
- private void vol_ValueChanged(object sender, RoutedPropertyChangedEventArgs<double> e)
- {
- media.Volume = vol.Value;
- }
- private void pause_Click(object sender, RoutedEventArgs e)
- {
- if (media.CanPause)
- media.Pause();
- }
- private void stop_Click(object sender, RoutedEventArgs e)
- {
- media.Stop();
- }
- private void mute_Click(object sender, RoutedEventArgs e)
- {
- if (media.IsMuted == true)
- {
- media.IsMuted = false;
- }
- else
- {
- media.IsMuted = true;
- }
- }
- }
- }
0 comments:
Post a Comment