zoukankan      html  css  js  c++  java
  • android 播放Raw文件夹下的音乐文件

    1、方法一

    public void onCreate(Bundle savedInstanceState) {
         
    super.onCreate(savedInstanceState); setContentView(R.layout.main); MediaPlayer mPlayer = MediaPlayer.create(FakeCallScreen.this, R.raw.mysoundfile); mPlayer.start(); } public void onDestroy() { mPlayer.stop(); super.onDestroy(); }

     2、方法二:

    A SoundPool is a collection of samples that can be loaded into memory from a resource inside the APK or from a file in the file system. The SoundPool library uses the MediaPlayer service to decode the audio into a raw 16-bit PCM mono or stereo stream. This allows applications to ship with compressed streams without having to suffer the CPU load and latency of decompressing during playback.

    /**
     * How many sounds can be played at once.
     */
    private static final int MAX_SOUND_POOL_STREAMS = 4;
    
    /**
     * Modify this as part of your own priority scheme. Higher numbers mean higher
     * priority. If you don't care, it's okay to use the same priority for every
     * sound.
     */
    private static final int NORMAL_PRIORITY = 10;
    
    private int mySoundId;
    
    @Override
    public void setupContent() {
        this.soundPool = new SoundPool(MAX_SOUND_POOL_STREAMS,
                AudioManager.STREAM_MUSIC, 100);
        this.mySoundId = this.soundPool.load(this.getApplicationContext(),
                R.raw.mySound, 1);
    }
    
    @Override
    private void playMySound() {
        this.soundPool.play(this.mySoundId, 1, 1, NORMAL_PRIORITY, 0, 1);
    }
  • 相关阅读:
    JavaScript表单验证年龄
    PHP会话处理相关函数介绍
    SpringCloud(第一天)
    springboot加强
    SpringBoot的第一个demo
    ElasticSearch(分布式全文搜索引擎)
    Redis集群
    NoSql和Redis
    ElementUI实现CRUD(修改前端页面),前后台解决跨域问题
    SSM+ElementUI综合练习和Swagger和postman的使用(第二天)
  • 原文地址:https://www.cnblogs.com/ikaka/p/3630669.html
Copyright © 2011-2022 走看看