예제 #1
0
        public void PlayTrack(Track track)
        {
            var path = Path.Combine (NSBundle.MainBundle.ResourcePath, "testsound.mp3");
            var data = System.IO.File.ReadAllBytes (path);
            var url = NSUrl.FromFilename (path);
            var status = MusicPlayerStatus.Success;
            player = MusicPlayer.Create (out status);
            player.MusicSequence = new MusicSequence ();
            player.MusicSequence.LoadFile (url, MusicSequenceFileTypeID.Any);
            player.Start ();
            /*AppDelegate.Player = AVAudioPlayer.FromUrl (url);
            AppDelegate.Player.NumberOfLoops = 1;

            var res = AppDelegate.Player.PrepareToPlay ();
            //player.AddPeriodicTimeObserver (CoreMedia,CMTime.FromSeconds (1, 1), );

            var r = AppDelegate.Player.Play ();
            AppDelegate.Player.DecoderError += (sender, e) => {
                var a = 3;
            };
            AppDelegate.Player.FinishedPlaying += (sender, e) => {
                var a = 4;
            };
            AppDelegate.Player.BeginInterruption += (sender, e) => {
                var a = 5;
            };
            AppDelegate.Player.EndInterruption += (sender, e) => {
                var a = 6;
            };
            */
        }
예제 #2
0
        public Track GetTrackInfo(string path)
        {
            Process mplayer = new Process ();
            mplayer.StartInfo.CreateNoWindow = true;
            mplayer.StartInfo.UseShellExecute = false;
            mplayer.StartInfo.ErrorDialog = false;
            mplayer.StartInfo.RedirectStandardOutput = true;
            mplayer.StartInfo.RedirectStandardInput = true;
            mplayer.StartInfo.RedirectStandardError = true;

            mplayer.StartInfo.FileName = MPLAYER_COMMAND;
            mplayer.StartInfo.Arguments = "-vo null -ao null -frames 0 -identify " + path;
            //mplayer.StartInfo.Arguments = "-identify " + filename;

            mplayer.Start ();
            // DANGER! WOLVES AHEAD!
            //TODO: may take REALLY long time or never exit if the file is unreacheable through network for some reason
            mplayer.WaitForExit ();

            var result = new Track ();
            result.Source = path;

            while (!mplayer.StandardOutput.EndOfStream) {
                var line = mplayer.StandardOutput.ReadLine ();
                var tagLinePrefix = "ID_CLIP_INFO_NAME";
                if (line.StartsWith (tagLinePrefix)) {
                    int separatorPos = line.IndexOf ('=');
                    // var tagId = line.Substring (tagLinePrefix.Length, separatorPos - tagLinePrefix.Length);
                    var tagName = line.Substring (separatorPos + 1);

                    line = mplayer.StandardOutput.ReadLine ();
                    separatorPos = line.IndexOf ('=');

                    var tagValue = line.Substring (separatorPos + 1);
                    switch (tagName) {
                    case "Title":
                        result.Name = tagValue;
                        break;
                    case "Artist":
                        result.Artist = tagValue;
                        break;
                    }
                }

                if (line.StartsWith ("ID_LENGTH")) {
                    int separatorPos = line.IndexOf ('=');
                    var seconds = Double.Parse (line.Substring (separatorPos + 1), System.Globalization.CultureInfo.InvariantCulture);
                    result.Duration = TimeSpan.FromSeconds (seconds);
                }
            }

            if (!(result.Duration.TotalSeconds > 0))
                result = null;

            return result;
        }
예제 #3
0
파일: VkApiService.cs 프로젝트: Grawl/hubbl
		public async Task<IEnumerable<Track>> GetUserAudioList (int offset, int count)
		{
			// Create an HTTP web request using the URL:
			var request = new HttpClient();
			var content = new FormUrlEncodedContent (
				new Dictionary<string, string>()
				{
					{"owner_id", _user.VkUserInfo.VkUserId},
					{"access_token", _user.VkUserInfo._token},
					{"count", count.ToString ()}
				});
			string responceString = "";
			try {
				var responceRaw = await request.PostAsync (_baseUrl + "audio.get",content);
				var bytes = await responceRaw.Content.ReadAsByteArrayAsync();
				responceString = System.Text.Encoding.GetEncoding ("windows-1251").GetString (bytes, 0, bytes.Length);
			

			JArray VkAudioListJSon = (JArray)JObject.Parse (responceString) ["response"] ;

			var responce = new List<Track>();
			
			foreach (var i in VkAudioListJSon.Skip (1)) {
				try {
				var track = new Track ();
				track.Id = (string)i ["aid"];
				track.Artist = (string)i ["artist"];
				track.Name = (string)i ["title"];
				track.Duration = TimeSpan.FromSeconds((double)(int)i ["duration"]);
				track.Source = (string)i ["url"];
				track.SourceType = SourceType.VK;
				track.Genre = (string)i ["genre"];

				responce.Add (track); 
				}
				catch (Exception e) {
					continue;
				}
			}
				return responce;
			}
			catch (Exception e) {
				return new List<Track> ();
			}


			}
예제 #4
0
 public MPlayerBackend()
 {
     _currentTrack = null;
     _currentTask = null;
     _taskCancellationTokenSource = new CancellationTokenSource ();
 }
예제 #5
0
        void IMusicPlayerBackend.PlayTrack(Track track)
        {
            if (_currentTrack != null)
                _currentTrack = null;
            if (_currentTask != null) {
                _taskCancellationTokenSource.Cancel ();
                _currentTask = null;
            }

            if (track == null)
                return;
            var cancellationToken = _taskCancellationTokenSource.Token;
            _currentTrack = track;
            _currentTrackStartTime = new TimeSpan ();
            _currentTrack.Current = new TimeSpan(0);
            _currentTask = Task.Run (() => {
                Process mplayer = new Process ();
                mplayer.StartInfo.UseShellExecute = false;
                mplayer.StartInfo.ErrorDialog = false;
                mplayer.StartInfo.RedirectStandardOutput = true;
                mplayer.StartInfo.RedirectStandardInput = true;
                mplayer.StartInfo.RedirectStandardError = true;

                mplayer.StartInfo.FileName = MPLAYER_COMMAND;
                mplayer.StartInfo.Arguments = track.Source; // + " -endpos 00:00:08";

                // cancellationToken.ThrowIfCancellationRequested ();
                mplayer.Start ();

                // while (!(cancellationToken.IsCancellationRequested || mplayer.HasExited)) {
                while (!mplayer.HasExited) {
                    Thread.Sleep (100);
                    //MEGAZALEPA
                    Console.WriteLine (mplayer.StandardOutput.ReadToEnd ());
                }

                if (!mplayer.HasExited)
                    mplayer.Kill ();
            });
        }
예제 #6
0
파일: HubblPlayer.cs 프로젝트: Grawl/hubbl
        public PlaylistEntry QueueTrack(User user, Track track)
        {
            UpdateUserPriorities ();

            if (!_usersActivities.ContainsKey (user.Id)) {
                var newActivity = new UserActivitiesRecord () {
                    basePriority = 1.0,
                    activitiesCount = 0,
                    lastActivityTime = DateTime.Now
                };
                _usersActivities.Add (user.Id, newActivity);
            }
            var activitiesRecord = _usersActivities [user.Id];

            if (activitiesRecord.activitiesCount++ == 0)
                ++_activeUsersCount;

            var entry = new PlaylistEntry () {
                User = user,
                Track = track,
                Id = _freeEntryId++,
                LikesNum = 0,
                DislikesNum = 0,
                Priority = activitiesRecord.basePriority
            };
            activitiesRecord.basePriority *= Math.Pow (0.5, track.Duration.TotalMilliseconds / AVG_TRACK_LENGTH_MS);
            _usersMarkedByEntryId.Add (entry.Id, new List<string> ());
            _usersMarkedByEntryId [entry.Id].Add (user.Id);

            Playlist.Add (entry);
            Playlist.Sort (comparePlaylistEntries);

            _playlistEntries.Add (entry);

            if (!_playing)
                Play ();

            return entry;
        }