첨부 소스 코드는 나눔고딕코딩 폰트를 사용합니다.
728x90
반응형
728x170

TestProject.zip
다운로드

▶ MainWindow.xaml

<Window x:Class="TestProject.MainWindow"
    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"    
    Width="800"
    Height="600"
    Title="MediaElement 클래스 사용하기"
    FontFamily="나눔고딕코딩"
    FontSize="16">
    <Grid Margin="10 10 10 10">
        <Grid.RowDefinitions>
            <RowDefinition Height="100*" />
            <RowDefinition Height="10"    />
            <RowDefinition Height="30"   />
        </Grid.RowDefinitions>
        <Border Grid.Row="0"
            BorderBrush="Black"
            BorderThickness="1">
            <MediaElement x:Name="mediaElement"
                LoadedBehavior="Manual"
                UnloadedBehavior="Manual"
                ScrubbingEnabled="True"/>
        </Border>
        <StackPanel Grid.Row="2"
            Orientation="Horizontal"
            HorizontalAlignment="Center">
            <Button x:Name="openButton"
                Width="100"
                Margin="0,0,10,0"
                Content="열기" />
            <Button x:Name="playButton"
                Width="100"
                Margin="0,0,10,0"
                Content="재생" />
            <Button x:Name="stopButton"
                Width="100"
                Margin="0,0,10,0"
                Content="중단" />
        </StackPanel>
    </Grid>
</Window>

 

728x90

 

▶ MainWindow.xaml.cs

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

namespace TestProject
{
    /// <summary>
    /// 메인 윈도우
    /// </summary>
    public partial class MainWindow : Window
    {
        //////////////////////////////////////////////////////////////////////////////////////////////////// Constructor
        ////////////////////////////////////////////////////////////////////////////////////////// Public

        #region 생성자 - MainWindow()

        /// <summary>
        /// 생성자
        /// </summary>
        public MainWindow()
        {
            InitializeComponent();

            this.openButton.Click += openButton_Click;
            this.playButton.Click += playButton_Click;
            this.stopButton.Click += stopButton_Click;
        }

        #endregion

        //////////////////////////////////////////////////////////////////////////////////////////////////// Method
        ////////////////////////////////////////////////////////////////////////////////////////// Private
        //////////////////////////////////////////////////////////////////////////////// Event

        #region 열기 버튼 클릭시 처리하기 - openButton_Click(sender, e)

        /// <summary>
        /// 열기 버튼 클릭시 처리하기
        /// </summary>
        /// <param name="sender">이벤트 발생자</param>
        /// <param name="e">이벤트 인자</param>
        private void openButton_Click(object sender, RoutedEventArgs e)
        {
            OpenFileDialog openFileDialog = new OpenFileDialog();

            openFileDialog.Title  = "미디어 소스";
            openFileDialog.Filter = "미디어 파일|*.avi;*.wmv";

            if(openFileDialog.ShowDialog(this).GetValueOrDefault() == true)
            {
                this.mediaElement.Source = new Uri(openFileDialog.FileName);

                this.mediaElement.Pause();
            }   
        }

        #endregion
        #region 재생 버튼 클릭시 처리하기 - playButton_Click(sender, e)

        /// <summary>
        /// 재생 버튼 클릭시 처리하기
        /// </summary>
        /// <param name="sender">이벤트 발생자</param>
        /// <param name="e">이벤트 인자</param>
        private void playButton_Click(object sender, RoutedEventArgs e)
        {
            this.mediaElement.Play();
        }

        #endregion
        #region 중단 버튼 클릭시 처리하기 - stopButton_Click(sender, e)

        /// <summary>
        /// 중단 버튼 클릭시 처리하기
        /// </summary>
        /// <param name="sender">이벤트 발생자</param>
        /// <param name="e">이벤트 인자</param>
        private void stopButton_Click(object sender, RoutedEventArgs e)
        {
            this.mediaElement.Stop();
        }

        #endregion
    }
}
728x90
반응형
그리드형(광고전용)
Posted by icodebroker

댓글을 달아 주세요