Android第三次作业

项目截图:

播放控制功能关键代码:

btnStop = (Button) findViewById(R.id.btn_stop);
        btnStop.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                try {
                    musicService.stop();
                    flag = 1;
                } catch (Exception e) {
                    return;
                }

            }
        });

        btnLast = (Button) findViewById(R.id.btn_last);
        btnLast.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                try {
                    musicService.last();
                } catch (Exception e) {
                    return;
                }

            }
        });

        btnNext =  findViewById(R.id.btn_next);
        btnNext.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                try {
                    musicService.next();
                } catch (Exception e) {
                    return;
                }

            }
        });

 

播放方法:

public void play() {
        try {
            player.reset();
            String dataSource = musicList.get(songNum);
            setPlayName(dataSource);
            player.setAudioStreamType(AudioManager.STREAM_MUSIC);
            player.setDataSource(dataSource);
            player.prepare();
            player.start();
            player.setOnCompletionListener(new MediaPlayer.OnCompletionListener() {
                public void onCompletion(MediaPlayer arg0) {
                    next();
                }
            });

        } catch (Exception e) {
            Log.v("MusicService", e.getMessage());
        }
    }

 

 

项目地址:https://coding.net/u/Trip1eL/p/Android_MusicPlayer/git/tree/master

apk:https://coding.net/u/Trip1eL/p/Android_MusicPlayer/git/raw/master/app.apk

posted @ 2018-12-11 21:18  Trip1eL  阅读(106)  评论(0编辑  收藏  举报