import android.media.MediaPlayer;
public class Mainactivity extends AppCompatActivity{
MediaPlayer mediaPlayer;
public void play(View view){
mediaPlayer.start();
Does ' MediaPlayer mediaPlayer;
' same as MediaPlayer mediaPlayer = New MediaPlayer();
? If not, what does ' MediaPlayer mediaPlayer;
' do?
No, it's not the same.
MediaPlayer mediaPlayer;
mediaPlayer = new MediaPlayer();
would be the same as MediaPlayer mediaPlayer = new MediaPlayer();
The MediaPlayer mediaPlayer;
is a declaration of this variable. It lets you instantiate it (create an object) at a different time than the declaration of this variable - for example in a constructor or a method.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.