gpt4 book ai didi

java - 音频文件在 Android Studio 模拟器中播放,但在我的实际手机 (LG ARISTO 2 PLUS) 上播放

转载 作者:行者123 更新时间:2023-12-02 08:36:21 25 4
gpt4 key购买 nike

音频文件在 Android Studio Emulator 中播放,但不在我的实际手机上播放。

使用android studio中的媒体播放器播放.mp3文件。在模拟器中一切正常...但是将 .apk 导出到我的手机后,.mp3 文件根本无法播放。非常感谢任何帮助

这是我的主要 Activity 文件:

import javax.swing.text.View;

public class MainActivity extends AppCompatActivity {
TextView plainText; // sets variable for plaintext which user enters
TextView textView;
MediaPlayer mediaPlayer;

public void select(View view) {

plainText = findViewById(R.id.editText);// why is this necessary for activity to run
textView = findViewById(R.id.textView);
mediaPlayer = MediaPlayer.create(this, R.raw.alarm);
try {
int time = Integer.parseInt(plainText.getText().toString());

int milliSecond = time * 1000;
// value is needed in milliseconds so we convert value into milliseconds
new CountDownTimer(milliSecond, 1000) {// 1000ms is 1 second

@Override
public void onTick(long millisUnitFinished) {
textView.setText("0.0" + String.valueOf(millisUnitFinished / 1000));

}

public void onFinish() {
textView.setText("Times Up!");
mediaPlayer.start();

}

}.start();

} catch (NumberFormatException e) {
Toast.makeText(this, "Enter Value in integer Only", Toast.LENGTH_LONG).show();
}

}

public void stop(View view) {
mediaPlayer.stop();
}

@Override // overide command basically overides the mainactivity externsion from mainactivity
// class so that it can run its own methods without
// essentially being bound by main activity classes extension
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);

}

}

最佳答案

您忘记添加

更改mediaPlayer = MediaPlayer.create(this, R.raw.alarm);

至:mediaPlayer = new MediaPlayer().create(this, R.raw.alarm);

关于java - 音频文件在 Android Studio 模拟器中播放,但在我的实际手机 (LG ARISTO 2 PLUS) 上播放,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/54602607/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com