public void Play(MusicFileItem item) { if (item == currentItem) { if (Bass.BASS_ChannelIsActive(stream) == BASSActive.BASS_ACTIVE_PLAYING) { Bass.BASS_ChannelPause(stream); currentItem.IsPlaying = false; timer.Stop(); } else { Bass.BASS_ChannelPlay(stream, false); currentItem.IsPlaying = true; timer.Start(); } return; } if (currentItem != null) { currentItem.VuValue = 0; currentItem.IsPlaying = false; } if (Bass.BASS_ChannelIsActive(stream) == BASSActive.BASS_ACTIVE_PLAYING) { Bass.BASS_StreamFree(stream); } currentItem = item; if (item.IsRemote) { var client = new TcpClient(); client.Connect(TransferViewModel.device.Address, 8000); var ns = client.GetStream(); byte[] buffer = Encoding.UTF8.GetBytes("receive:" + item.Path); ns.Write(buffer, 0, buffer.Length); ns.Flush(); var handle = GCHandle.Alloc(client); stream = Bass.BASS_StreamCreateFileUser(BASSStreamSystem.STREAMFILE_BUFFER, BASSFlag.BASS_DEFAULT, fileproc, (IntPtr)handle); } else { stream = Bass.BASS_StreamCreateFile(item.Path, 0, 0, BASSFlag.BASS_DEFAULT); } currentItem.IsPlaying = Bass.BASS_ChannelPlay(stream, false); timer.Start(); }
public async void NavigateRemote(string path) { RemotePath = path; RemoteFiles.Clear(); var json = await SendCommand("list:" + path); JArray array; try { array = JArray.Parse(json); } catch { return; } var temp = new List <FileItem>(); foreach (var obj in array) { var rpath = obj.Value <string>("path"); var folder = obj.Value <bool>("folder"); if (!folder && mss.currentItem != null && mss.currentItem.Path.Equals(rpath)) { temp.Add(mss.currentItem); continue; } var name = obj.Value <string>("name"); long size = 0; if (!folder) { size = obj.Value <long>("size"); } var ext = Path.GetExtension(name).ToUpper(); if (ext.Length > 0) { ext = ext.Substring(1); } var date = new DateTime(1970, 1, 1, 0, 0, 0); date = date.AddMilliseconds(obj.Value <long>("date")); FileItem item; if (MusicFileItem.IsMusicFile(rpath)) { item = new MusicFileItem(); } else if (PictureFileItem.IsPictureFile(rpath)) { item = new PictureFileItem(); } else { item = new FileItem(); } item.Model = this; item.Path = rpath; item.Name = name; item.Size = size; item.Extension = folder ? "FOLDER" : ext; item.Date = date.ToString(); item.IsFolder = folder; item.IsRemote = true; temp.Add(item); } temp.Sort(new Comparison <FileItem>((t1, t2) => { if (t1.IsFolder && !t2.IsFolder) { return(-1); } else if (!t1.IsFolder && t2.IsFolder) { return(1); } return(string.Compare(t1.Name, t2.Name, true)); })); RemoteFiles = new ObservableCollection <FileItem>(temp); }
public void NavigateLocal(string path) { if (path == "/") { NavigateLocalHome(); return; } LocalPath = path; LocalDrive.Clear(); var di = new DirectoryInfo(path); if (!di.Exists) { return; } var dirs = di.EnumerateDirectories(); foreach (var dir in dirs) { if (dir.Attributes.HasFlag(FileAttributes.Hidden | FileAttributes.System)) { continue; } LocalDrive.Add(new FileItem() { Model = this, Path = dir.FullName, Name = dir.Name, Extension = "FOLDER", Date = dir.LastWriteTime.ToString(), IsFolder = true }); } var files = di.EnumerateFiles(); foreach (var file in files) { if (file.Attributes.HasFlag(FileAttributes.Hidden | FileAttributes.System)) { continue; } FileItem item; if (MusicFileItem.IsMusicFile(file.FullName)) { item = new MusicFileItem(); } else if (PictureFileItem.IsPictureFile(file.FullName)) { item = new PictureFileItem(); } else { item = new FileItem(); } item.Model = this; item.Path = file.FullName; item.Name = file.Name; item.Size = file.Length; item.Extension = file.Extension.Length >= 1 ? file.Extension.Substring(1).ToUpper() : ""; item.Date = file.LastWriteTime.ToString(); item.IsFolder = false; LocalDrive.Add(item); } }