示例#1
0
 public static void SetDownloadStatus(IEnumerable <PlaylistMusicItem> items, ulong bytesReceived)
 {
     foreach (var item in items)
     {
         MusicItem.SetDownloadStatus(item.Song, bytesReceived);
     }
 }
        /// <summary>
        ///
        /// </summary>
        /// <param name="doc"></param>
        /// <param name="track"></param>
        /// <returns>the URI of the tile image</returns>
        protected async Task <Uri> SetImage(XmlDocument doc, MusicItem track)
        {
            var imageUri = await GetCoverUriOrDefault(track);

            TileUtil.SetImage(doc, imageUri);
            return(imageUri);
        }
示例#3
0
        public virtual void UpdateStatus(PlaybackStatus status)
        {
            Playlist.Sync(status.Playlist, status.PlaylistIndex);
            var previousTrack = NowPlaying;
            var track         = status.Track;

            // avoids triggering unnecessary TrackChanged events
            // TODO so if the same track is queued in the playlist...
            if (track == null || previousTrack == null || track.Name != previousTrack.Name)
            {
                NowPlaying = track;
            }
            Volume = status.Volume;
            IsMute = status.IsMute;
            if (NowPlaying != null)
            {
                TrackPosition = status.TrackPosition;
                var       plist         = status.Playlist;
                var       playlistIndex = status.PlaylistIndex;
                var       songCount     = plist.Count();
                var       nextIndex     = playlistIndex + 1;
                MusicItem nextTrack     = null;
                if (nextIndex >= 0 && nextIndex < songCount)
                {
                    nextTrack = plist.ElementAt(nextIndex);
                }
                CurrentPlayerState = status.State;
                FeedbackMessage    = null;
            }
            else
            {
                CurrentPlayerState = PlayerState.Closed;
            }
        }
示例#4
0
        void LoadList()
        {
            SQLiteDataReader check = sql.ExecuteQuery("select name from sqlite_master where name='Music'");
            int i = 0;

            if (check.HasRows)
            {
                SQLiteDataReader reader = sql.ExecuteQuery("select ID,Name,Path from Music");
                if (reader.HasRows)
                {
                    while (reader.Read())
                    {
                        //ListViewItem lvi = new ListViewItem();
                        //lvi.Content = reader.GetString(0);
                        MusicItem m = new MusicItem();
                        m.Content = reader.GetString(1);
                        m.id      = reader.GetInt64(0);
                        m.name    = reader.GetString(1);
                        m.path    = reader.GetString(2);
                        MusicList.Items.Add(m);
                        i++;
                    }
                }
                reader.Close();
            }
            check.Close();
        }
示例#5
0
        private void Play(MusicItem track)
        {
            var uri       = track.Source;
            var uriString = uri.ToString();

            Debug.WriteLine($"Playing: {uriString}");

            // Start the background task if it wasn't running
            if (!IsMyBackgroundTaskRunning || MediaPlayerState.Closed == CurrentPlayer.CurrentState)
            {
                // First update the persisted start track
                ApplicationSettingsHelper.SaveSettingsValue(ApplicationSettingsConstants.TrackId, uriString);
                ApplicationSettingsHelper.SaveSettingsValue(ApplicationSettingsConstants.Position, new TimeSpan().ToString());

                // Start task
                StartBackgroundAudioTask();
            }
            else
            {
                // Switch to the selected track
                MessageService.SendMessageToBackground(new TrackChangedMessage(uri));
            }

            if (MediaPlayerState.Paused == CurrentPlayer.CurrentState)
            {
                CurrentPlayer.Play();
            }
        }
示例#6
0
        public override Task SubmitDownload(MusicItem track)
        {
            // does intentionally not await completion of download
            var t = DownloadAsync(track);

            return(AsyncTasks.Noop());
        }
示例#7
0
 private Task TrySubmitDownload(MusicItem song)
 {
     return(TrySubmitDownload(new List <MusicItem>()
     {
         song
     }));
 }
示例#8
0
 public static async Task SetDurationIfZero(MusicItem track)
 {
     if (track.Duration.TotalSeconds < 1)
     {
         await SetDuration(track);
     }
 }
        protected async Task <Uri> SetImageAndMeta(XmlDocument doc, MusicItem track)
        {
            var uri = await SetImage(doc, track);

            SetMeta(doc, track);
            return(uri);
        }
示例#10
0
    void Start()
    {
        InitRandomItems();

        generateButton.onClick.AddListener(() => {
            ReGenerate();
        });
        




        nextGenerateBtn.onClick.AddListener(() =>
        {
            GenerateText();
        });

        toggleRootBtn.onClick.AddListener(()=>
        {
            rootParent.gameObject.SetActive(!rootParent.gameObject.activeInHierarchy);
        });


        for (int i = 0; i < 7; i++)
        {
            MusicItem musicItem = Instantiate<MusicItem>(prefab, rootParent);
            musicItem.musicName.text = musicNames[i];
            musicItem.numberName.text = numberNames[i];
            musicItem.singName.text = singNames[i];
        }
        GenerateText();
    }
示例#11
0
        int SearchMusic(string str)
        {
            DirectoryInfo    directory = new DirectoryInfo(str);
            Regex            reg       = new Regex("[.](mp3|wav)$");
            string           query;
            SQLiteDataReader reader = sql.ExecuteQuery("select name from sqlite_master where name='Music'");

            if (!reader.HasRows)
            {
                sql.ExecuteQuery("CREATE TABLE Music( ID INTEGER PRIMARY KEY AUTOINCREMENT,Name TEXT NOT NULL,Path TEXT NOT NULL);");
            }
            foreach (FileInfo finfo in directory.GetFiles())
            {
                if (!reg.IsMatch(finfo.Name))
                {
                    continue;
                }
                MusicItem m = new MusicItem();
                m.Content = finfo.Name;
                m.path    = str;
                m.name    = finfo.Name;
                MusicList.Items.Add(m);
                query = "INSERT INTO Music(Name,Path)VALUES('" + finfo.Name + "','" + str + "');";
                sql.ExecuteQuery(query);
            }
            reader.Close();
            return(0);
        }
示例#12
0
 private void OnTrackChanged(MusicItem track)
 {
     if (TrackChanged != null)
     {
         TrackChanged(track);
     }
 }
示例#13
0
 public override async Task Upload(MusicItem song, string resource, PimpSession destSession)
 {
     var targetUri = destSession.BaseUri + resource;
     var cmd       = new BeamCommand(song.Id, targetUri, destSession.Username, destSession.Password);
     // Bug: If the upload takes about over one minute, the client-side
     // response of HttpClient says 404 even though the server has returned
     // 200 OK. Increasing HttpClient.Timeout has no effect.
     // Displaying an error when all is fine is confusing so we suppress the
     // exception until this is resolved properly. This might of course also
     // suppress 404s that are actually real.
     await Utils.SuppressAsync <NotFoundException>(async() => {
         var versionResponse = await session.PingAuth();
         var serverVersion   = new Version(versionResponse.version);
         try {
             // throws BadRequestException if adding fails
             await session.PostCommand(cmd, "/playback/stream");
         } catch (InternalServerErrorException) {
             // MusicPimp server 2.0.0 and lower throw InternalServerError if the MusicBeamer endpoint uses https because
             // StartSSL certs are not trusted. Fixed in MusicPimp server 2.1.0.
             if (destSession.BaseUri.StartsWith("https") && serverVersion < PimpSessionBase.HttpsSupportingVersion)
             {
                 MessagingService.Instance.Send("An error occurred. Please upgrade the MusicPimp server to version 2.1.1 or later. Get it from www.musicpimp.org. Thanks!");
             }
             else
             {
                 throw;
             }
         }
     });
 }
示例#14
0
 public Task WriteAsync(string file, MusicItem data)
 {
     return(Task.Factory.StartNew(() =>
     {
         To(data).Write(file);
     }));
 }
示例#15
0
        /// <summary>
        /// Updates the tile. Called when the app is initialized and whenever the track changes.
        ///
        /// </summary>
        /// <param name="track">the track, which may be null</param>
        /// <param name="init">true if this method is called because the app is being initialized, false otherwise</param>
        /// <returns></returns>
        public async Task UpdateTileAndBackground(MusicItem track, bool init = false)
        {
            try {
                if (track != null)
                {
                    await Update(track);

                    var maybeCover = await Covers.TryGetCover(track);

                    if (maybeCover != null)
                    {
                        await SetBackground(maybeCover);
                    }
                }
                else
                {
                    await UpdateNoTrack();

                    if (init)
                    {
                        var uri = await SetRandomBackground();

                        //if(uri == null) {
                        //    await SetBackground(DefaultBackgroundUri);
                        //}
                    }
                }
            } catch (Exception) {
                // suppresses the exception intentionally, what is the user supposed to do anyway if this fails?
                // it fails occasionally with some absurd COM Exception message
                //MessagingService.Instance.Send("Failed to update tile or unable to send toast. " + e.Message);
            }
        }
示例#16
0
        /// <summary>
        /// Starts playback based on the preferred URI of the supplied track.
        ///
        /// Note that only remote or app-local URIs can directly be used as
        /// the Source of the underlying MediaElement. If the URI points to
        /// an non-app-local file path, we need to supply a FileStream as the
        /// MediaElement Source instead of a URI.
        ///
        /// The app furthermore needs to have been assigned permissions
        /// to access the local source of the track, if any. An exception
        /// is thrown if that is not the case.
        ///
        /// </summary>
        /// <param name="track">track to play</param>
        public async Task SetTrack(MusicItem track)
        {
            DisposeNullifyAndSuppress(sourceStream);
            // check local file availability
            latestTrack = track;
            var maybeLocalUri = await MultiFolderLibrary.Instance.LocalUriIfExists(track);

            Uri sourceUri = maybeLocalUri != null ? maybeLocalUri : track.Source;

            try {
                var file = await StoreFileUtils.GetFile(sourceUri);

                if (file != null)
                {
                    // Bugfix: setting an ms-appdata URI directly to the Source when
                    // the music source is remote sometimes throws an exception about Metadata, so we avoid that.
                    // The identical ms-appdata URI seems to work if the music source is local.
                    // The root cause is unresolved atm.
                    await SetSource(file);
                }
                else
                {
                    Player.Source = sourceUri;
                }
            } catch (FileNotFoundException) {
                // StoreFileUtils.GetFile throws FNFE if the file has special characters such as scandics (...)
                // even if it exists, so this is a bugfix for now
                Player.Source = track.Source;
            }

            // sets universal media control meta data
            MediaControl.TrackName  = Utils.EmptyIfNull(track.Name);
            MediaControl.ArtistName = Utils.EmptyIfNull(track.Artist);
        }
示例#17
0
 private void Start()
 {
     Directory.CreateDirectory(Application.persistentDataPath + "/Success");
     File.Create(Application.persistentDataPath + "/Success.txt");
     backBtn.onClick.AddListener(() => {
         if (musicDetailUI.gameObject.activeInHierarchy)
         {
             foreBg.SetActive(true);
             musicDetailUI.gameObject.SetActive(false);
             lastMusicItem = null;
             selectedItem  = null;
             SoundManager.manager.StopMusic();
         }
         else
         {
             IndexUICtrl.instance.SetPageType(PageType.Index);
             selectedTypeItem = null;
             lastTypeItem     = null;
         }
     });
     playTypeBtn.onClick.AddListener(() => {
         playType = (PlayType)(((int)playType + 1) % 4);
     });
     InitMusic();
 }
示例#18
0
 public override async Task <Uri> LocalUriIfExists(MusicItem track)
 {
     if (track.IsSourceLocal)
     {
         return(track.Source);
     }
     return(await Choose(track, async lib => await lib.LocalUriIfExists(track)));
 }
示例#19
0
 public MusicItemViewModel(DragAndDropContext dragAndDropContext, double x, double y)
 {
     DragAndDropContext = dragAndDropContext;
     ItemPath           = dragAndDropContext.MusicItemViewModel.ItemPath;
     (X, Y)             = (x, y);
     MusicItem          = new MusicItem(ItemPath, x, y);
     IsInToolbox        = false;
 }
示例#20
0
        public override void BeforeSquareWideUpdate(XmlDocument doc, MusicItem track, Uri imageUri)
        {
            var largeXml = TileUpdateManager.GetTemplateContent(TileTemplateType.TileSquare310x310ImageAndText02);

            TileUtil.SetImage(largeXml, imageUri);
            SetMeta(largeXml, track, includeAlbum: false);
            TileUtil.Embed(src: largeXml, dest: doc);
        }
        public async Task SetTrack(MusicItem track)
        {
            Uri localUri = await PhoneLocalLibrary.Instance.LocalUriIfExists(track);

            Uri source = localUri != null ? localUri : track.Source;

            Player.Track = AudioItemConversions.item2track(track, source);
        }
示例#22
0
        protected override async Task EnsureHasDuration(MusicItem track)
        {
            var maybeLocalUri = await MultiFolderLibrary.Instance.LocalUriIfExists(track);

            var uri = maybeLocalUri == null ? track.Source : maybeLocalUri;

            track.Duration = await MediaElement.UriDuration(uri);
        }
示例#23
0
 public override async Task <Uri> LocalUriIfExists(MusicItem track)
 {
     if (track.IsSourceLocal)
     {
         return(track.Source);
     }
     return(await LocalUriForIfExists(track.Path, (ulong)track.Size));
 }
示例#24
0
        public override async Task Update(MusicItem track)
        {
            var imageUri = await GetCoverUriOrDefault(track);

            PhoneTileUtil.UpdateTileCyclic(GetLongContent(track), new List <Uri> {
                imageUri
            });
        }
        public rename_usercontrol(MusicItem _item)
        {
            this.InitializeComponent();

            item = _item;

            RenameTxb.Text = item.title;
        }
示例#26
0
 public PimpTrack(MusicItem item)
 {
     id       = item.Id;
     title    = item.Name;
     artist   = item.Artist;
     album    = item.Album;
     size     = item.Size;
     duration = item.Duration.TotalSeconds;
 }
示例#27
0
        public override async Task Upload(MusicItem song, string resource, PimpSession destSession)
        {
            var lib = await FindLibrary(song.Path);

            if (lib != null)
            {
                await lib.Upload(song, resource, destSession);
            }
        }
示例#28
0
        public override async Task SetPlaylist(MusicItem song)
        {
            // TODO remove
            await SubmitDownload(song);

            var newPlaylist = new PlaylistInfo(AudioConversions.ToPlaylistTrack(song));

            await SavePlaylist(newPlaylist);
        }
示例#29
0
        private async Task SubmitFolder(MusicItem folder)
        {
            var tracks = await MusicProvider.SongsInFolder(folder);

            foreach (var item in tracks)
            {
                await SubmitDownload(item);
            }
        }
示例#30
0
        protected override async Task EnsureHasDuration(MusicItem track)
        {
            var uri = await LocalLibrary.LocalUriIfExists(track);

            if (uri != null)
            {
                track.Duration = await StoreBeamPlayer.MediaElement.UriDuration(uri);
            }
        }
示例#31
0
        static List<IMediaFile> LoadSongsFor(MusicItem item)
        {
            SortedList<string, IMediaFile> albumSongs;
            string key;

            if (item is SongMusicItem) {
                List<IMediaFile> single = new List<IMediaFile> ();
                single.Add (item as SongMusicItem);
                return single;
            }

            albumSongs = new SortedList<string, IMediaFile> ();
            foreach (SongMusicItem song in indexer.Songs) {
                switch (item.GetType ().Name) {
                case "AlbumMusicItem":
                    if (item.Name != song.Album) continue;
                    break;
                case "ArtistMusicItem":
                    if (item.Name != song.Artist) continue;
                    break;
                }

                key = string.Format ("{0}-{1}-{2}", song.Album, song.Track, song.Path);
                try {
                    if (albumSongs.ContainsKey (key)) continue;
                    albumSongs.Add (key, song);
                } catch (Exception e) {
                    Log.Error ("{0} : {1}", key, e.Message);
                }
            }

            return new List<IMediaFile> (albumSongs.Values);
        }
示例#32
0
        public static List<SongMusicItem> LoadSongsFor(MusicItem item)
        {
            SortedList<string, SongMusicItem> songs;

            //case where we're loading all the songs for a given song
            //is trivially just that one song
            if (item is SongMusicItem) {
                List<SongMusicItem> single = new List<SongMusicItem> ();
                single.Add (item as SongMusicItem);
                return single;
            }

            songs = new SortedList<string, SongMusicItem> ();
            foreach (SongMusicItem song in LoadAllSongs ()) {
                switch (item.GetType ().Name) {
                    case "AlbumMusicItem":
                        if (item.Name != song.Album) continue;
                    break;
                    case "ArtistMusicItem":
                        if (item.Name != song.Artist) continue;
                    break;
                }
                try {
                    songs.Add (song.Name, song);
                } catch { }
            }
            List<SongMusicItem> newlist = new List<SongMusicItem>();
            foreach(SongMusicItem song in songs.Values){
                newlist.Add(song);
            }
            return newlist;
        }