-
Notifications
You must be signed in to change notification settings - Fork 0
/
Mp3Player.cs
109 lines (99 loc) · 3.26 KB
/
Mp3Player.cs
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
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
using System;
using System.Collections.Generic;
using System.Linq;
using System.Runtime.InteropServices;
using System.Text;
using System.Threading.Tasks;
using Windows.UI.Xaml.Controls;
namespace MediaPlayer
{
class Mp3Player
{
public Artist CurrentArtist = null;
public Album CurrentAlbum = null;
public Song CurrantSong = null;
public Playlist CurrentPlaylist = null;
private int CurrantSongIndex = 0;
public List<Artist> artists { get; set; }
public List<Song> songs { get; set; }
public List<Playlist> playlists { get; set; }
//Xaml UI elements
public ListViewState listViewState;
public MediaElement mPlayer { get; set; }
public Image image { get; set; }
public TextBlock title { get; set; }
public TextBlock artis { get; set; }
public bool Repeat = false;
public bool Shuffel = false;
public void SetListViewState(ListViewState listview)
{
listViewState = listview;
}
public void SongHasEnded()
{
if (listViewState.GetState().Equals("Album"))
{
TriggerSongPlay(CurrentAlbum.songs[NextSongLogic()]);
}
if (listViewState.GetState().Equals("Songs"))
{
TriggerSongPlay(songs[NextSongLogic()]);
}
}
public void TriggerSongPlay(Song song)
{
CurrantSong = song;
CurrantSongIndex = GetSongIndex(CurrantSong);
song.Play(mPlayer, image, title, artis);
}
private int NextSongLogic()
{
if (Repeat)
{
//do nothing
}
else if (Shuffel)
{
if (listViewState.GetState().Equals("Songs"))
{
Random random = new Random();
CurrantSongIndex = random.Next(0, songs.Count() - 1);
}
if (listViewState.GetState().Equals("Album"))
{
Random random = new Random();
CurrantSongIndex = random.Next(0, CurrentAlbum.songs.Count() - 1);
}
}
else
{
if (listViewState.GetState().Equals("Songs") && CurrantSongIndex < songs.Count() - 1)
{
++CurrantSongIndex;
}
else if (listViewState.GetState().Equals("Album") && CurrantSongIndex < CurrentAlbum.songs.Count() - 1)
{
++CurrantSongIndex;
}
else
{
CurrantSongIndex = 0;
}
}
return CurrantSongIndex;
}
private int GetSongIndex(Song song)
{
int index = 0;
if (listViewState.GetState().Equals("Album"))
{
index = CurrentAlbum.songs.IndexOf(song);
}
if (listViewState.GetState().Equals("Songs"))
{
index = songs.IndexOf(song);
}
return index;
}
}
}