050321 ランダム
 ホーム | 日記 | プロフィール 【フォローする】 【ログイン】

shebapgのブログ

shebapgのブログ

【毎日開催】
15記事にいいね!で1ポイント
10秒滞在
いいね! --/--
おめでとうございます!
ミッションを達成しました。
※「ポイントを獲得する」ボタンを押すと広告が表示されます。
x

PR

カレンダー

日記/記事の投稿

バックナンバー

2024年06月
2024年05月
2024年04月
2024年03月
2024年02月

お気に入りブログ

スザンヌの「ぶろぐ… スザンヌ☆さん
気持ち 田中将大ブ… 田中 将大さん

キーワードサーチ

▼キーワード検索

購入履歴

2009年03月02日
XML
今日からプログで作成したプログラムを覚書き程度に書いていこうと思います。

今回はVisual Stdio 2008 C#でMediaElementコントロールを使用した簡単なプログ
ラムを掲載します。

プログラムはWPFアプリケーションで作成しています。

Window1.xaml

<Window x:Class="WpfMediaPlayer.Window1"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
Title="MediaPlayer" Height="107" Width="300">
<Grid>
  <Button Height="23" HorizontalAlignment="Left" Margin="10,10,0,0" Name="btFile" VerticalAlignment="Top" Width="100" Click="btFile_Click">音楽ファイル選択</Button>
  <Button Height="23" Margin="114,10,117,0" Name="btPlay" VerticalAlignment="Top" Click="btPlay_Click" Visibility="Visible" IsEnabled="False">再生</Button>
  <Button Height="23" HorizontalAlignment="Right" Margin="0,10,66,0" Name="btStop" VerticalAlignment="Top" Width="47" Click="btStop_Click" IsEnabled="False">停止</Button>
  <Label Background="Aquamarine" Height="24" Margin="10,39,40,0" Name="label3" VerticalAlignment="Top" />
  <MediaElement Height="24" HorizontalAlignment="Right" Margin="0,39,12,0" Name="mediaElement1" VerticalAlignment="Top" Width="28" />
</Grid>
</Window>


Window1.xaml.cs


using System;
using System.Windows;
using System.Windows.Controls;
using Microsoft.Win32;

  namespace WpfMediaPlayer
  {
    public partial class Window1 : Window
    {
    public Window1()
    {
      InitializeComponent();
    }
    private void btFile_Click(object sender, RoutedEventArgs e)
    {
      OpenFileDialog ofd = new OpenFileDialog();
      ofd.Filter = "MP3|*.mp3";
      if (ofd.ShowDialog() == true)
      {
        string strFile = ofd.FileName;
        label3.Content = strFile;
        mediaElement1.Source = new Uri(strFile, UriKind.Absolute);
        mediaElement1.LoadedBehavior = MediaState.Manual;
        btPlay.IsEnabled = true;
        btStop.IsEnabled = true;
      }
    }

    private void btPlay_Click(object sender, RoutedEventArgs e)
    {
      mediaElement1.Play();
    }

    private void btStop_Click(object sender, RoutedEventArgs e)
    {
      mediaElement1.Stop();
    }
  }
}








お気に入りの記事を「いいね!」で応援しよう

最終更新日  2009年03月04日 11時50分47秒
[コンピュータプログラム] カテゴリの最新記事



© Rakuten Group, Inc.