You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
87 lines
1.8 KiB
87 lines
1.8 KiB
4 years ago
|
using System;
|
||
|
using System.Collections;
|
||
|
using System.Collections.Generic;
|
||
|
using UnityEngine;
|
||
|
|
||
|
namespace AX.AudioSystem
|
||
|
{
|
||
|
/// <summary>
|
||
|
/// 表示一个播放列表。
|
||
|
/// </summary>
|
||
|
public class PlayList : IEnumerable<Track>
|
||
|
{
|
||
|
private Deque<Track> deque;
|
||
|
|
||
|
public PlayList()
|
||
|
{
|
||
|
deque = new Deque<Track>();
|
||
|
}
|
||
|
|
||
|
public int Count { get { return deque.Count; } }
|
||
|
|
||
|
public void Add(Track track)
|
||
|
{
|
||
|
deque.Add(track);
|
||
|
}
|
||
|
|
||
|
public void Add(string filename, bool played, bool playing)
|
||
|
{
|
||
|
var track = new Track();
|
||
|
|
||
|
track.Filename = filename;
|
||
|
track.Played = played;
|
||
|
track.Playing = playing;
|
||
|
|
||
|
deque.Add(track);
|
||
|
}
|
||
|
|
||
|
public bool Remove(string filename)
|
||
|
{
|
||
|
var index = IndexOf(filename);
|
||
|
|
||
|
if (index == -1)
|
||
|
return false;
|
||
|
|
||
|
deque.RemoveAt(index);
|
||
|
|
||
|
return true;
|
||
|
}
|
||
|
|
||
|
public int IndexOf(string filename)
|
||
|
{
|
||
|
var index = -1;
|
||
|
|
||
|
for (var i = 0; i < deque.Count; ++i)
|
||
|
{
|
||
|
if (deque[i].Filename == filename)
|
||
|
{
|
||
|
index = i;
|
||
|
break;
|
||
|
}
|
||
|
}
|
||
|
|
||
|
return index;
|
||
|
}
|
||
|
|
||
|
public void Clear()
|
||
|
{
|
||
|
deque.Clear();
|
||
|
}
|
||
|
|
||
|
public Track this[int index]
|
||
|
{
|
||
|
get { return deque[index]; }
|
||
|
set { deque[index] = value; }
|
||
|
}
|
||
|
|
||
|
public IEnumerator<Track> GetEnumerator()
|
||
|
{
|
||
|
return deque.GetEnumerator();
|
||
|
}
|
||
|
|
||
|
IEnumerator IEnumerable.GetEnumerator()
|
||
|
{
|
||
|
return this.GetEnumerator();
|
||
|
}
|
||
|
}
|
||
|
}
|