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

TestSolution.zip
다운로드
TestSolution.z01
다운로드

[TestProject 프로젝트]

▶ MainForm.cs

using System;
using System.Windows.Forms;

using TestLibrary;

namespace TestProject
{
    /// <summary>
    /// 메인 폼
    /// </summary>
    public partial class MainForm : Form
    {
        //////////////////////////////////////////////////////////////////////////////////////////////////// Constructor
        ////////////////////////////////////////////////////////////////////////////////////////// Public

        #region 생성자 - MainForm()

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

            this.streamPlayerControl.StreamStarted += streamPlayerControl_StreamStarted;
            this.streamPlayerControl.StreamStopped += streamPlayerControl_StreamStopped;
            this.streamPlayerControl.StreamFailed  += streamPlayerControl_StreamFailed;
            this.playButton.Click                  += playButton_Click;
            this.stopButton.Click                  += stopButton_Click;
            this.imageButton.Click                 += imageButton_Click;
        }

        #endregion

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

        #region 스트림 재생기 컨트롤 스트림 시작시 처리하기 - streamPlayerControl_StreamStarted(sender, e)

        /// <summary>
        /// 스트림 재생기 컨트롤 스트림 시작시 처리하기
        /// </summary>
        /// <param name="sender">이벤트 발생자</param>
        /// <param name="e">이벤트 인자</param>
        private void streamPlayerControl_StreamStarted(object sender, EventArgs e)
        {
            SetButtonEnabled();

            this.statusTextBox.Text = "재생";
        }

        #endregion
        #region 스트림 재생기 컨트롤 스트림 중단시 처리하기 - streamPlayerControl_StreamStopped(sender, e)

        /// <summary>
        /// 스트림 재생기 컨트롤 스트림 중단시 처리하기
        /// </summary>
        /// <param name="sender">이벤트 발생자</param>
        /// <param name="e">이벤트 인자</param>
        private void streamPlayerControl_StreamStopped(object sender, EventArgs e)
        {
            SetButtonEnabled();

            this.statusTextBox.Text = "중단";
        }

        #endregion
        #region 스트림 재생기 컨트롤 스트림 실패시 처리하기 - streamPlayerControl_StreamFailed(sender, e)

        /// <summary>
        /// 스트림 재생기 컨트롤 스트림 실패시 처리하기
        /// </summary>
        /// <param name="sender">이벤트 발생자</param>
        /// <param name="e">이벤트 인자</param>
        private void streamPlayerControl_StreamFailed(object sender, StreamFailedEventArgs e)
        {
            SetButtonEnabled();

            this.statusTextBox.Text = "실패";

            MessageBox.Show(e.Error, "에러", MessageBoxButtons.OK, MessageBoxIcon.Error);
        }

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

        /// <summary>
        /// 재생하기 버튼 클릭시 처리하기
        /// </summary>
        /// <param name="sender">이벤트 발생자</param>
        /// <param name="e">이벤트 인자</param>
        private void playButton_Click(object sender, EventArgs e)
        {
            var uri = new Uri(this.urlTextBox.Text);

            this.streamPlayerControl.StartPlay(uri);

            this.statusTextBox.Text = "연결중...";
        }

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

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

        #endregion
        #region 이미지 버튼 클릭시 처리하기 - imageButton_Click(sender, e)

        /// <summary>
        /// 이미지 버튼 클릭시 처리하기
        /// </summary>
        /// <param name="sender">이벤트 발생자</param>
        /// <param name="e">이벤트 인자</param>
        private void imageButton_Click(object sender, EventArgs e)
        {
            SaveFileDialog saveFileDialog = new SaveFileDialog();

            saveFileDialog.Filter = "비트맵 이미지|*.bmp";

            if(saveFileDialog.ShowDialog() == DialogResult.OK)
            {
                this.streamPlayerControl.GetCurrentFrame().Save(saveFileDialog.FileName);
            }
        }

        #endregion

        //////////////////////////////////////////////////////////////////////////////// Function

        #region 버튼 이용 가능 여부 설정하기 - SetButtonEnabled()

        /// <summary>
        /// 버튼 이용 가능 여부 설정하기
        /// </summary>
        private void SetButtonEnabled()
        {
            this.playButton.Enabled  = !this.streamPlayerControl.IsPlaying;
            this.stopButton.Enabled  = this.streamPlayerControl.IsPlaying;
            this.imageButton.Enabled = this.streamPlayerControl.IsPlaying;
        }

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

댓글을 달아 주세요