반응형

애니메이션 플레이어를 사용해 보자.

 

씬에 스프라이트를 추가하고 텍스쳐를 지정한다.

 

애니메이션 플레이어를 추가한다.

 

애니메이션 탭에서 Animation 버튼을 클릭하고 New를 선택한다.

 

애니메이션 이름(ani_1)을 지정한다.

 

Add Track - Property Track을 선택한다.

 

Sprite2D를 선택한다.

 

position을 선택한다.

 

애니메이션 탭 - position 트랙에서 마우스 오른쪽 클릭 - Insert Key 선택

 

키가 만들어지면 0초로 옮기고, 스프라이트를 이동해서 키를 하나 더 만들어 1초로 옮긴다.

 

스프라이트에 스크립트를 추가한다.

 

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
using Godot;
 
public partial class Control : Sprite2D
{
    public AnimationPlayer Player;
 
    public override void _Ready()
    {
        Player = GetNode<AnimationPlayer>("../AnimationPlayer");
    }
 
    public override void _Process(double delta)
    {
        if (Input.IsActionJustPressed("ui_accept"))
            Player.Play("ani_1");
    }
}
 

 

추가된 스크립트에 위와 같은 코드를 작성한다.

 

게임을 실행하고 엔터키를 누르면 애니메이션이 플레이된다.

 

※ 참고

Animation

 

반응형
Posted by J-sean
:
반응형

C#에서 Windows Media Player를 이용해 오디오 파일을 플레이 해 보자.

 

아래 링크를 참고해 Windows Media Player COM Component를 가져오고 빌드시 메세지가 발생하지 않도록 하자.

(Windows Media Player 컴포넌트를 폼에 배치할 필요는 없다)

2021.11.21 - [C#] - C# Windows Media Player Audio/Video Play #1

 

폼과 버튼을 적당히 배치한다.

 

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
 
using WMPLib;
 
namespace WindowsFormsApp1
{
    public partial class Form1 : Form
    {
        private string time;
 
        WindowsMediaPlayer wmp;
 
        public Form1()
        {
            InitializeComponent();
            
            wmp = new WindowsMediaPlayer();
 
            Timer T = new Timer();
            T.Interval = 1000;
            T.Tick += new EventHandler(Form1_Timer);
            T.Start();
        }
 
        private void Form1_Timer(object sender, System.EventArgs e)
        {
            if (wmp.playState == WMPPlayState.wmppsPlaying)
            {
                //time = wmp.controls.currentPositionString + " / " + wmp.controls.currentItem.durationString;
                //time = wmp.controls.currentPosition.ToString() + " / " + wmp.controls.currentItem.duration.ToString();
                time = TimeSpan.FromSeconds((int)wmp.controls.currentPosition).ToString() + " / "
                    + TimeSpan.FromSeconds((int)wmp.controls.currentItem.duration);
 
                Graphics G = CreateGraphics();
                //G.DrawString(time, Font, System.Drawing.Brushes.Black, 20, 70); // 글자가 겹친다.
                TextRenderer.DrawText(G, time, Font, new Point(2070), ForeColor, BackColor);
                G.Dispose();
            }
        }
 
        private void button1_Click(object sender, EventArgs e)
        {
            try
            {
                OpenFileDialog dlg = new OpenFileDialog();
                if (dlg.ShowDialog() == DialogResult.OK)
                {
                    wmp.URL = dlg.FileName;
                }
            }
            catch (Exception exc)
            {
                MessageBox.Show(exc.Message);
            }
        }
 
        private void button2_Click(object sender, EventArgs e)
        {
            if (wmp.playState == WMPPlayState.wmppsPlaying)
            {
                wmp.controls.stop();
            }
        }
    }
}
 

 

소스를 입력한다.

 

오디오/비디오 파일을 플레이 할 수 있다. (비디오 파일은 오디오만 출력된다)

실행 파일과 함께 Interop.WMPLib.dll 파일이 존재해야 한다.

 

Using the Windows Media Player Control in a .NET Framework Solution

 

반응형
Posted by J-sean
:
반응형

 

2021.11.21 - [C#] - C# Windows Media Player Audio/Video Play #2

 

C#에서 Windows Media Player를 이용해 오디오/비디오 파일을 플레이 해 보자.

 

Toolbox의 원하는 곳에서 우클릭 - Choose Items...

 

COM Components - Windows Media Player 선택.

 

폼, 버튼, Windows Media Player를 적당히 배치한다.

 

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
 
using WMPLib;
 
namespace WindowsFormsApp1
{
    public partial class Form1 : Form
    {
        public Form1()
        {
            InitializeComponent();
        }
 
        private void button1_Click(object sender, EventArgs e)
        {
            try
            {
                OpenFileDialog dlg = new OpenFileDialog();
                if (dlg.ShowDialog() == DialogResult.OK)
                {
                    axWindowsMediaPlayer1.URL = dlg.FileName;
                    axWindowsMediaPlayer1.Ctlcontrols.stop();   // 자동 재생 방지.
                    // The managed-code wrapper for the Windows Media Player control exposes
                    // the Controls object as Ctlcontrols to avoid collision with the Controls
                    // property inherited from System.Windows.Forms.Control.
                }
            }
            catch (Exception exc)
            {
                MessageBox.Show(exc.Message);
            }
        }
    }
}
 

 

소스를 입력한다.

 

 

이대로 빌드해도 문제는 없지만 위와 같은 메세지가 나온다.

 

References - WMPLib - Properties - Embed Interop Types - False 선택

다시 빌드하면 아무 메세지도 나오지 않는다.

 

MP3등 오디오 파일 재생.

 

AVI, MP4등 비디오 파일 재생.

 

 

이번엔 실행하면 아무것도 보이지 않다가 오디오/비디오 파일을 선택하면 UI없이 플레이 하는 프로그램을 만들어 보자.

 

폼, 버튼, Windows Media Player를 배치한다.

 

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
 
using WMPLib;
 
namespace WindowsFormsApp1
{
    public partial class Form1 : Form
    {
        public Form1()
        {
            InitializeComponent();
 
            axWindowsMediaPlayer1.Visible = false;
            axWindowsMediaPlayer1.uiMode = "none";
        }
 
        private void button1_Click(object sender, EventArgs e)
        {
            try
            {
                OpenFileDialog dlg = new OpenFileDialog();
                if (dlg.ShowDialog() == DialogResult.OK)
                {
                    axWindowsMediaPlayer1.URL = dlg.FileName;
                    axWindowsMediaPlayer1.Visible = true;
                }
            } catch (Exception exc)
            {
                MessageBox.Show(exc.Message);
            }
        }
 
        private void button2_Click(object sender, EventArgs e)
        {
            if (axWindowsMediaPlayer1.playState == WMPPlayState.wmppsPlaying)
            {
                axWindowsMediaPlayer1.Ctlcontrols.stop();
                // The managed-code wrapper for the Windows Media Player control exposes
                // the Controls object as Ctlcontrols to avoid collision with the Controls
                // property inherited from System.Windows.Forms.Control.
                
                axWindowsMediaPlayer1.Visible = false;
            }            
        }
    }
}
 

 

소스를 입력하고 빌드한다.

 

WMP가 보이지 않는다. Play 버튼을 클릭하고 비디오 파일을 선택한다.

 

비디오가 UI없이 플레이된다.

 

실행 파일과 함께 Interop.WMPLib.dll 파일이 존재해야 한다.

 

Using the Windows Media Player Control in a .NET Framework Solution

 

반응형
Posted by J-sean
:

C# Media Player Mp3

C# 2021. 11. 21. 13:27 |
반응형

C#에서 MP3파일을 플레이 해 보자.

 

Solution Explorer - References 우클릭 - Add Reference... 클릭

 

PresentationCore 선택.

 

WindowsBase 선택.

 

폼과 버튼을 적당히 배치한다.

 

 

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
 
using System.Windows.Media;
 
namespace WindowsFormsApp1
{
    public partial class Form1 : Form
    {
        enum STATE {PLAYING, STOPPED, PAUSED }
 
        STATE state;
        private string time;
 
        MediaPlayer MP;
 
        public Form1()
        {
            InitializeComponent();
 
            state = STATE.STOPPED;
            MP = new MediaPlayer();
 
            Timer T = new Timer();
            T.Interval = 1000;
            T.Tick += new EventHandler(Form1_Timer);
            T.Start();            
        }
 
        private void Form1_Timer(object sender, System.EventArgs e)
        {
            if (state == STATE.PLAYING && MP.NaturalDuration.HasTimeSpan)
            {
                time = MP.Position.ToString(@"hh\:mm\:ss"+ " / "
                    + MP.NaturalDuration.TimeSpan.ToString(@"hh\:mm\:ss");
 
                Graphics G = CreateGraphics();
                //G.DrawString(time, Font, System.Drawing.Brushes.Black, 20, 90); // 글자가 겹친다.
                TextRenderer.DrawText(G, time, Font, new Point(2090), ForeColor, BackColor);
                G.Dispose();
            }            
        }
 
        private void button1_Click(object sender, EventArgs e)
        {
            try
            {
                OpenFileDialog dlg = new OpenFileDialog();
                if (dlg.ShowDialog() == DialogResult.OK)
                {
                    MP.Open(new Uri(dlg.FileName));
                    MP.Play();
                    state = STATE.PLAYING;
                }
            } catch (Exception exc)
            {
                MessageBox.Show(exc.Message);
            }            
        }
 
        private void button2_Click(object sender, EventArgs e)
        {
            MP.Stop();
            MP.Close();
            state = STATE.STOPPED;
        }
    }
}
 

 

소스를 입력한다.

 

프로그램을 실행하고 파일을 선택하면 플레이 된다.

 

반응형
Posted by J-sean
:
반응형

리눅스(우분투) 서버 같은 콘솔 환경에서도 비디오 플레이어를 사용할 수 있다.


mpv를 설치한다.


--vo=drm 옵션, 영상 파일 이름과 함께 실행한다.


자막 파일이 있다면 자막도 표시된다. 주요 단축키 목록은 아래와 같다.


  • LEFT and RIGHT: Seek backward/forward 5 seconds. Shift+arrow does a 1 second exact seek

  • UP and DOWN: Seek forward/backward 1 minute. Shift+arrow does a 5 second exact seek

  • p / SPACE: Pause (pressing again unpauses).

  • q: Stop playing and quit.

  • Q: Like q, but store the current playback position. Playing the same file later will resume at the old playback position if possible.

  • 9 and 0: Decrease/increase volume.

  • m: Mute sound.

  • o (also P): Show progression bar, elapsed time and total duration on the OSD.

  • O: Toggle OSD states between normal and playback time/duration.

  • v: Toggle subtitle visibility.

  • z and Z: Adjust subtitle delay by +/- 0.1 seconds. The x key does the same as Z currently, but use is discouraged.

  • r and R: Move subtitles up/down. The t key does the same as R currently, but use is discouraged.

  • s: Take a screenshot.

  • S: Take a screenshot, without subtitles. (Whether this works depends on VO driver support.)

  • Shift+PGUP and Shift+PGDWN: Seek backward or forward by 10 minutes. (This used to be mapped to PGUP/PGDWN without Shift.)

  • 1 and 2: Adjust contrast.

  • 3 and 4: Adjust brightness.

  • 5 and 6: Adjust gamma.

  • 7 and 8: Adjust saturation.


반응형
Posted by J-sean
:
반응형

리눅스(우분투) 서버 같은 콘솔 환경에서도 Ogg, MP3, WAV 등의 음악 파일을 재생 할 수 있다.


cmus(C* Music Player)를 설치한다.


설치가 완료되면 cmus를 실행한다.


cmus가 실행되고 아무것도 표시되지 않는다. 방향키, 엔터등을 눌러도 아무런 반응이 없지만 당황하지 말고 숫자 5를 누른다.


Browser가 표시된다. 음악 파일이 있는 디렉토리로 이동한다.



원하는 파일에서 엔터키를 누르면 플레이 된다. 하지만 선택한 1개의 파일만 플레이 되므로 간단한 사용방법을 알아 보자.


각 파일에서 a키(add to library)를 눌러 준다. (y키를 누르면 playlist로 추가된다)


숫자 1을 누른다. Library 화면이 표시되고 위에서 add한 파일이 모두 추가 되었다. 원하는 곡에서 엔터키를 눌러 플레이 할 수 있다. (Artist/Album과 Track은 Tab키로 이동한다)


숫자 2를 누르면 Sorted 화면이 표시된다.



숫자 3을 누르면 Playlist 화면이 표시된다.


숫자 4를 누르면 Queue 화면이 표시된다. Queue에 추가(e)되는 노래는 순서를 무시하고 지금 재생되는 노래 다음에 재생된다. 재생 후 queue에서 자동 삭제된다.


숫자 5를 누르면 Browser 화면이 표시된다.


숫자 6을 누르면 Filters 화면이 표시된다.



숫자 7을 누르면 Settings 화면이 표시된다. 각 단축키를 확인할 수 있다. 아래는 주요 단축키 목록이다.

  • x: play

  • v: stop

  • c: pause

  • b: next

  • z: prev

  • right: seek +5

  • left: seek -5

  • -: vol -10%

  • +/=: vol +10%

  • C(대문자): toggle continue

  • r: toggle repeat

  • s: toggle shuffle

  • t: toggle show_remaining_time

  • a: add(to library)

  • e: add(to queue)

  • y: add(to playlist)

  • delete: remove

  • q: quit


WAV 파일은 aplay로 간단히 재생할 수 있다.


반응형
Posted by J-sean
:
반응형

아래 링크의 제품과 거의 같지만 조금 더 심플한 MP3 디코더다. 


2020/11/29 - [Review] - MP3 Decoder with Built-in Amplifier Module


스위치나 터미널이 달려 있지 않아 그냥 사용하기 불편할 수 있지만 원하는 형태의 MP3 플레이어를 만들기는 더 좋다.


Micro SD카드 슬롯만 있는 작고 간단한 형태의 MP3 디코더 보드.


Pin assignment


1. V33REG DVDD33: Digital power 3.3V.

2. V50REG VMCU/BAT: Lithium battery input, 3.3V~5V.

3. VSSREG DVSS: Digital ground.

4. DACOL DACL: Left audio signal output.

5. VCOM: Center audio signal Vref, please plug 1uF capacitor voltage.

6. DACOR DACR: Right channel audio output.

7. LINEIN_R LineInR + L: LineIn left + right input.

8. IOA4: AD-key buttons.

9. IOA3 FMCLK: If IOA3 pull-down resistor to ground, IOA3 will output clock signal to the outside Hanging FM radio IC. If IOA3 is vacant, FM radio IC will take their 32768Hz crystal.

10. IOA2 Mute: Mute the external amplifier.

11. DM: USB of DM.

12. DP: USB of DP.

13. IOA0: IO-key/LED.

(1) Plug-in LED light: Output “1” represents the lit LED.

(2) IO-key1.

(3) Options are used to define the key mode.

14. IOB1 SD_CLK: Clock output T card/SD card. SD_DET: detecting whether there is an SD card is inserted, to read “0” on behalf of insertion. Please connect a 3.3KΩ resistance.

15. IOB0 SD_CMD: T card/SD card command and response. I2C_CLK: I2C the clock; the external EEPROM, and FM.

16. IOB2 SD_DAT: data input T card/SD Card/output. I2C_DAT: I2C of data; and external EEPROM FM.


3.7V 배터리나 (USB)5V 전원으로 작동 가능하며 Micro SD 카드에 듣고 싶은 음악을 담아 플레이 할 수 있다. 위 다이어그램과 같이 스위치와 4Ω 3W 스피커를 연결해 사용한다.


■ Previous/Volume--: 이전 곡 / 길게 누르면(약 2초) 소리 작게

■ Play/Stop: 플레이 / 정지

■ Next/Volume++: 다음 곡 / 길게 누르면 소리 크게


반응형
Posted by J-sean
:
반응형

컴퓨터에 사운드 카드가 기본 사양이 되기 전, 큰 결심을 하고서야 구입할 수 있었던 옥소리나 사운드 블래스터등의 고가 사운드 카드를 컴퓨터에 설치하고 듣던 게임 음악은 정말 놀라웠다. 삐~ 소리만 나는 줄 알았던 컴퓨터에서 이런 소리가 날 수 있다니..


옥소리(사운드 카드)를 광고하는 옥소리(배우)


옥소리 사운드 카드


그리고는 MP3로 대표되는 여러가지 오디오 압축 포맷 덕분에 작은 용량으로도 많은 노래를 저장할 수 있게 되었고 컴퓨터가 아닌 작은 기기에서도 노래를 재생할 수 있는 플레이어들이 등장하기 시작했다. 물론 저렴한 가격은 아니었던거 같다.


최초의 MP3 플레이어


지금은 중국에서 한국까지 오는 배송비를 포함해도 천원이 조금 넘는 저렴한 가격에 MP3 디코더를 구입해 직접 간단한 MP3 플레이어를 만들 수 있다.



앰프가 포함된 MP3 디코더


알리 익스프레스에서는 Nondestructive Decoder Board 라는 이름으로 판매되고 있다. 왜 nondestructive 일까.. 무슨 의미로 nondestructive를 붙인걸까.. 알 수가 없다.


어쨌든 USB 2.0 type A, Micro 5 pin, 또는 3.7~5.5V 배터리로 작동 가능하며 Micro SD 카드에 듣고 싶은 음악을 담아 플레이 할 수 있다. 3.5mm 이어폰 잭을 연결하거나 4Ω 3W의 스피커를 연결해 듣는다.


■ Prev/V--: 이전 곡 / 길게 누르면(약 2초) 소리 작게

■ Next/V++: 다음 곡 / 길게 누르면 소리 크게

■ P/P/Mode: 플레이 / 정지, 길게 누르면 U Disk, Micro SD 카드 전환 (U Disk는 5V 전원 필요)

■ Repeat: 1곡 반복 / 전체 반복


U Disk를 지원한다고 적혀 있어서 FAT, FAT32 파일 시스템으로 포맷한 USB 드라이브에 음악음 담아 시도해 봤지만 플레이 되지 않았다. Micro SD 카드는 문제없이 플레이 되었다.


간단한 MP3 플레이어가 필요한 경우 유용하게 사용할 수 있을거 같다.


※ 참고: 2020/12/09 - [Review] - MP3 Decoder with Built-in Amplifier Module (GPD2846A)


반응형
Posted by J-sean
: