Android Studio:使用或覆盖已弃用的API

时间:2019-07-12 04:03:51

标签: android

我似乎找不到问题,我对android工作室也很陌生。谢谢您的帮助

private String songId = "";
private String title = "";
private String artist = "";
private String fileLink = "";
private String coverArt = "";
private String url = "";

private MediaPlayer player = null;

private Button btnPlayPause = null;

private SongCollection songCollection = new SongCollection();

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_play_song);

    btnPlayPause = findViewById(R.id.btnPlayPause);

    retrieveData();

    displaySong(title, artist, coverArt);
}

private void retrieveData() {
    Bundle songData = this.getIntent().getExtras();

    songId = songData.getString("id");
    title = songData.getString("title");
    artist = songData.getString("artist");
    fileLink = songData.getString("fileLink");
    coverArt = songData.getString("coverArt");

    url = BASE_URL + fileLink;
}

private void displaySong(String title, String artist, String coverArt) {
    TextView txtTitle = findViewById(R.id.txtSongTitle);
    txtTitle.setText(title);
    TextView txtArtist = findViewById(R.id.txtArtist);
    txtArtist.setText(artist);
    int imageId = AppUtil.getImageIdFromDrawable(this, coverArt);
    ImageView ivCoverArt = findViewById(R.id.imgCoverArt);
    ivCoverArt.setImageResource(imageId);

}

private void preparePlayer() {
    player = new MediaPlayer();
    try {
        player.setAudioStreamType(AudioManager.STREAM_MUSIC);

        player.setDataSource(url);

        player.prepare();
    } catch (IOException e) {
        e.printStackTrace();
    }
}

public void playorPauseMusic(View view) {
    if (player == null) {
        preparePlayer();
    }
    if (!player.isPlaying()) {
        if (musicPosition > 0) {
            player.seekTo(musicPosition);
        }

        player.start();

        btnPlayPause.setText("Pause");

        setTitle("Now Playing " + title + "-" + artist);

        gracefullyStopWhenMusicEnds();
    }
    else
    {
        pauseMusic();
    }
}

private void pauseMusic() {
    player.pause();

    musicPosition = player.getCurrentPosition();
    btnPlayPause.setText("PLAY");
}

private void gracefullyStopWhenMusicEnds() {
    player.setOnCompletionListener(new MediaPlayer.OnCompletionListener() {
        @Override
        public void onCompletion(MediaPlayer mediaPlayer) {
            stopActivities();
        }
    });
}

当我运行音乐播放器时,我会使用或覆盖已弃用的API。 使用-Xlint:deprecation重新编译以获取详细信息。

所有这些事情都是在我创建了一个新文件并将以前工作中的文件粘贴到

之后发生的

0 个答案:

没有答案