bool IsEndTrack() { bool res = (_player.controls.currentPosition >= _player.controls.currentItem.duration && _player.controls.currentItem.duration > 0) || (_saveTrack == Track && _player.controls.currentPosition <= 0 && _savePos > 0 && !_isChangeTrack); _saveTrack = _track; _savePos = _player.controls.currentPosition; return res; }
public static void GetGroupTracks(MusiсDir dir, long offset, Action<IList<Track>> callback) { var method = "audio.get"; var param = new Dictionary<string, object>(); param["offset"] = offset.ToString(); param["count"] = 100; param["owner_id"] = "-" + dir.Gid; param["version"] = @"5.34"; using (var wc = new WebClient()) { //wc.Proxy.Credentials = CredentialCache.DefaultCredentials; wc.DownloadStringCompleted += (s, e) => { if (e.Result != null) { var result = new List<Track>(); var json = new JavaScriptSerializer().Deserialize<Dictionary<string, object>>(e.Result); var root = json["response"] as ArrayList; foreach (var dirInfo in root) //if (dirInfo is Dictionary<string, object>) { var tmp = dirInfo as Dictionary<string, object>; if (tmp != null && tmp.ContainsKey("aid") && tmp.ContainsKey("url") && tmp.ContainsKey("artist") && tmp.ContainsKey("duration") && tmp.ContainsKey("title")) { var track = new Track() { Tid = (int)tmp["aid"], MusicDirID = dir.MusicDirID, TrackAuthor = tmp["artist"] as string, TrackDuration = (int)tmp["duration"], TrackUrl = tmp["url"] as string, TrackName = tmp["title"] as string }; result.Add(track); } } callback(result); } }; wc.DownloadStringAsync(Request(method, param)); } }
public void SaveTrackInDB(Track track) { Context.Tracks.Add(track); Context.SaveChanges(); }
public void SaveTrack(Track track, Action<Track> callback) { using (var wc = new WebClient()) { wc.DownloadDataCompleted += (sender, args) => { var dirRoot = Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.UserProfile), "Music", "EMusic"); //Context.Settings.Where(s => s.Key.Equals(SettingsStr.DirSaveTracks)).FirstOrDefault(); if (!Directory.Exists(dirRoot)) Directory.CreateDirectory(dirRoot); track.MusiсDir = Context.MusiсDirs.FirstOrDefault(md => md.MusicDirID == track.MusicDirID); var tmp = track.MusiсDir.NameDir.Split('\\'); var dirPart = tmp[tmp.Length - 1].ToLower(); var dir = Path.Combine(dirRoot, dirPart); if (!Directory.Exists(dir)) Directory.CreateDirectory(dir); var finalPath = Path.Combine(dir, track.TrackName + ".mp3"); File.WriteAllBytes(finalPath, args.Result); track.TrackFileName = finalPath; track.TrackSave = 1; track.MusiсDir.PositiveRating++; Context.SaveChanges(); if (callback != null) callback(track); }; wc.DownloadDataAsync(new Uri(track.TrackUrl)); } }