当前位置:   article > 正文

鸿蒙播放音频_soundplayer.createsound

soundplayer.createsound

播放短视频

得到文件之后使用音频编辑软件进行编辑,得到将音频文件之后将这个文件放置到项目的midia文件夹中:

鸿蒙应用开发可以使用SoundPlayer播放音频文件:

private void startSound(float speed, OnPlayListener listener) {
  
  soundPlayer = new SoundPlayer(AudioManager.AudioVolumeType.STREAM_MUSIC.getValue());
   
    soundId = soundPlayer.createSound(getContext(), ResourceTable.Media_1tick);
    soundPlayer.setOnCreateCompleteListener((soundPlayer1, i, i1) -> {
        
        taskId = soundPlayer.play(soundId);
        soundPlayer.setVolume(taskId, 1.0f);
        soundPlayer.setLoop(taskId, -1); 
        soundPlayer.setPlaySpeedRate(taskId, speed);
        if(listener != null){
            listener.onPlay();
        }
    }
}
1.private void startSound(float speed, OnPlayListener listener) {
soundPlayer = new SoundPlayer(AudioManager.AudioVolumeType.STREAM_MUSIC.getValue());
soundId = soundPlayer.createSound(getContext(), ResourceTable.Media_1tick);
soundPlayer.setOnCreateCompleteListener((soundPlayer1, i, i1) -> {
taskId = soundPlayer.play(soundId);
soundPlayer.setVolume(taskId, 1.0f);
soundPlayer.setLoop(taskId, -1); 
soundPlayer.setPlaySpeedRate(taskId, speed);
if(listener != null){
listener.onPlay();
}
}
}
 

声明:本文内容由网友自发贡献,不代表【wpsshop博客】立场,版权归原作者所有,本站不承担相应法律责任。如您发现有侵权的内容,请联系我们。转载请注明出处:https://www.wpsshop.cn/w/你好赵伟/article/detail/773965
推荐阅读
相关标签
  

闽ICP备14008679号