protected override void OnCreate(Bundle savedInstanceState)
        {
            base.OnCreate(savedInstanceState);

            SetContentView(Resource.Layout.Song);

            //Helper class with the names of the mp3s
            Songs songs = new Songs();

            //These variables store the current song and songIndex
            string song      = Intent.GetStringExtra("songTitle");
            int    songIndex = Intent.GetIntExtra("songIndex", 0);

            StartSong(song);
            SetArtwork(song);

            // Display song name
            TextView songTitle = FindViewById <TextView>(Resource.Id.songTitle);

            songTitle.Text = Intent.GetStringExtra("songTitle");

            //Getting a hold of the image buttons. Get the rest of them
            ImageButton backButton = (ImageButton)FindViewById <ImageButton>(Resource.Id.back);
            ImageButton prevButton = (ImageButton)FindViewById <ImageButton>(Resource.Id.prevSong);

            //For the media controls, create the rest of the delegates for the image buttons
            //Here's the previous song button, for example
            prevButton.Click += delegate
            {
                if (songIndex != 0)
                {
                    //Make sure to save into the variables upon a button clicked to keep track of the song
                    song       = songs.GetSong(songIndex - 1);
                    songIndex -= 1;
                    SetArtwork(song);
                    StartSong(song);
                }
            };

            //For the back button, just go back to the main activity. If you want to be fancy, you can pass the media player so that the
            //song is still playing.
            backButton.Click += delegate {
            };
        }
        protected override void OnCreate(Bundle bundle)
        {
            base.OnCreate(bundle);

            // Set our view from the "main" layout resource
            SetContentView(Resource.Layout.Main);

            Songs songs    = new Songs();
            var   listView = FindViewById <ListView>(Resource.Id.songsList);
            var   adapter  = new ArrayAdapter(this, Resource.Layout.CustomListView, Android.Resource.Id.Text1, songs.GetSongs());

            listView.Adapter = adapter;

            listView.ItemClick += (sender, e) =>
            {
                var songActivity = new Intent(this, typeof(SongActivity));
                songActivity.PutExtra("songTitle", songs.GetSong(e.Position));
                songActivity.PutExtra("songIndex", e.Position);
                StartActivity(songActivity);
            };
        }
Beispiel #3
0
        protected override void OnCreate(Bundle savedInstanceState)
        {
            base.OnCreate(savedInstanceState);

            SetContentView(Resource.Layout.Song);

            Songs  songs     = new Songs();
            int    songIndex = Intent.GetIntExtra("songIndex", 0);
            string song      = songs.GetSong(songIndex);

            StartSong(song);

            ImageButton backButton   = (ImageButton)FindViewById <ImageButton>(Resource.Id.back);
            ImageButton prevButton   = (ImageButton)FindViewById <ImageButton>(Resource.Id.prevSong);
            ImageButton playButton   = (ImageButton)FindViewById <ImageButton>(Resource.Id.play);
            ImageButton nextButton   = (ImageButton)FindViewById <ImageButton>(Resource.Id.nextSong);
            ImageButton stopButton   = (ImageButton)FindViewById <ImageButton>(Resource.Id.stop);
            ImageButton pauseButton  = (ImageButton)FindViewById <ImageButton>(Resource.Id.pause);
            ImageButton recordButton = (ImageButton)FindViewById <ImageButton>(Resource.Id.record);

            prevButton.LongClick += delegate
            {
                StartSong(songs.GetSong(0));
            };

            prevButton.Click += delegate
            {
                if (songIndex != 0)
                {
                    song       = songs.GetSong(songIndex - 1);
                    songIndex -= 1;
                    StartSong(song);
                }
            };

            playButton.Click += delegate
            {
                if (isPaused)
                {
                    mediaPlayer.Start();
                }
                if (isStopped)
                {
                    StartSong(songs.GetSong(songIndex));
                }
                isPaused  = false;
                isStopped = false;
            };

            nextButton.Click += delegate
            {
                if (songIndex != 2)
                {
                    song       = songs.GetSong(songIndex + 1);
                    songIndex += 1;
                    StartSong(song);
                }
            };

            nextButton.LongClick += delegate
            {
                StartSong(songs.GetSong(2));
            };

            stopButton.Click += delegate
            {
                if (mediaPlayer.IsPlaying)
                {
                    mediaPlayer.Stop();
                }
                isStopped = true;
            };

            pauseButton.Click += delegate
            {
                if (mediaPlayer.IsPlaying)
                {
                    mediaPlayer.Pause();
                }
                isPaused = true;
            };

            recordButton.Click += delegate
            {
                if (mediaPlayer.IsPlaying)
                {
                    if (!isRecording)
                    {
                        recordButton.BackgroundTintList = GetColorStateList(Resource.Color.red);
                        mediaRecorder = new MediaRecorder();
                        isRecording   = true;
                        mediaRecorder.SetAudioSource(AudioSource.Mic);
                        mediaRecorder.SetOutputFormat(OutputFormat.ThreeGpp);
                        mediaRecorder.SetOutputFile(Android.OS.Environment.ExternalStorageDirectory + "/" + song + ".3gp");
                        mediaRecorder.SetAudioEncoder(AudioEncoder.AmrNb);
                        mediaRecorder.Prepare();
                        mediaRecorder.Start();
                    }
                    else
                    {
                        isRecording = false;

                        try
                        {
                            mediaRecorder.Stop();
                        } catch (Exception e)
                        {
                            Console.WriteLine(e);
                        }

                        mediaRecorder.Release();
                        mediaRecorder = null;
                    }
                }
            };

            backButton.Click += delegate
            {
                mediaPlayer.Release();
                StartActivity(new Intent(this, typeof(MainActivity)));
            };
        }