• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright 2018 The Android Open Source Project
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  *     http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  */
16 
17 package com.google.oboe.samples.rhythmgame;
18 
19 import android.content.Context;
20 import android.content.res.AssetManager;
21 import androidx.appcompat.app.AppCompatActivity;
22 
23 import android.media.AudioManager;
24 import android.os.Build;
25 import android.os.Bundle;
26 import android.view.WindowManager;
27 
28 public class MainActivity extends AppCompatActivity {
29 
30     // Used to load the 'native-lib' library on application startup.
31     static {
32         System.loadLibrary("native-lib");
33     }
34 
35     @Override
onCreate(Bundle savedInstanceState)36     protected void onCreate(Bundle savedInstanceState) {
37         super.onCreate(savedInstanceState);
38         setContentView(R.layout.activity_main);
39         getWindow().addFlags(WindowManager.LayoutParams.FLAG_KEEP_SCREEN_ON);
40         setDefaultStreamValues(this);
41     }
42 
onResume()43     protected void onResume(){
44         super.onResume();
45         native_onStart(getAssets());
46     }
47 
onPause()48     protected void onPause(){
49         super.onPause();
50         native_onStop();
51     }
52 
setDefaultStreamValues(Context context)53     static void setDefaultStreamValues(Context context) {
54         if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN_MR1){
55             AudioManager myAudioMgr = (AudioManager) context.getSystemService(Context.AUDIO_SERVICE);
56             String sampleRateStr = myAudioMgr.getProperty(AudioManager.PROPERTY_OUTPUT_SAMPLE_RATE);
57             int defaultSampleRate = Integer.parseInt(sampleRateStr);
58             String framesPerBurstStr = myAudioMgr.getProperty(AudioManager.PROPERTY_OUTPUT_FRAMES_PER_BUFFER);
59             int defaultFramesPerBurst = Integer.parseInt(framesPerBurstStr);
60 
61             native_setDefaultStreamValues(defaultSampleRate, defaultFramesPerBurst);
62         }
63     }
64 
native_onStart(AssetManager assetManager)65     private native void native_onStart(AssetManager assetManager);
native_onStop()66     private native void native_onStop();
native_setDefaultStreamValues(int defaultSampleRate, int defaultFramesPerBurst)67     private static native void native_setDefaultStreamValues(int defaultSampleRate,
68                                                       int defaultFramesPerBurst);
69 }
70