diff --git a/build.gradle b/build.gradle index d5ca043..b69f018 100644 --- a/build.gradle +++ b/build.gradle @@ -1,14 +1,14 @@ // Top-level build file where you can add configuration options common to all sub-projects/modules. buildscript { - ext.ftc_version = '4.0' + ext.ftc_version = '4.3' repositories { google() jcenter() } dependencies { - classpath 'com.android.tools.build:gradle:3.2.0' + classpath 'com.android.tools.build:gradle:3.2.1' classpath 'com.github.dcendents:android-maven-gradle-plugin:2.1' // NOTE: Do not place your application dependencies here; they belong // in the individual module build.gradle files diff --git a/library/build.gradle b/library/build.gradle index 36bc5e8..35fd495 100644 --- a/library/build.gradle +++ b/library/build.gradle @@ -8,7 +8,7 @@ android { targetSdkVersion 19 testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner" - versionCode 44 + versionCode 45 versionName "$ftc_version.0" ndk { diff --git a/library/src/main/AndroidManifest.xml b/library/src/main/AndroidManifest.xml index e190949..ce5cce0 100644 --- a/library/src/main/AndroidManifest.xml +++ b/library/src/main/AndroidManifest.xml @@ -1,7 +1,9 @@ + package="com.qualcomm.ftccommon" + android:versionCode="55" + android:versionName="8.9" > + + + diff --git a/library/src/main/java/com/qualcomm/ftccommon/FtcRobotControllerService.java b/library/src/main/java/com/qualcomm/ftccommon/FtcRobotControllerService.java index d7cbf65..8a4199f 100644 --- a/library/src/main/java/com/qualcomm/ftccommon/FtcRobotControllerService.java +++ b/library/src/main/java/com/qualcomm/ftccommon/FtcRobotControllerService.java @@ -367,10 +367,8 @@ public IBinder onBind(Intent intent) { NetworkType networkType = (NetworkType) intent.getSerializableExtra(NetworkConnectionFactory.NETWORK_CONNECTION_TYPE); webServer = new WebServer(networkType); - NetworkConnectionHandler networkConnectionHandler = NetworkConnectionHandler.getInstance(); - networkConnectionHandler.pushNetworkConnectionCallback(this); - networkConnection = NetworkConnectionFactory.getNetworkConnection(networkType, getBaseContext()); + networkConnection.setCallback(this); networkConnection.enable(); networkConnection.createConnection(); @@ -484,6 +482,7 @@ public synchronized void shutdownRobot() { @Override public CallbackResult onNetworkConnectionEvent(NetworkConnection.NetworkEvent event) { CallbackResult result = CallbackResult.NOT_HANDLED; + RobotLog.ii(TAG, "onNetworkConnectionEvent: " + event.toString()); switch (event) { case CONNECTED_AS_GROUP_OWNER: RobotLog.ii(TAG, "Wifi Direct - connected as group owner"); diff --git a/library/src/main/java/com/qualcomm/ftccommon/SoundPlayer.java b/library/src/main/java/com/qualcomm/ftccommon/SoundPlayer.java index ca388da..927a63d 100644 --- a/library/src/main/java/com/qualcomm/ftccommon/SoundPlayer.java +++ b/library/src/main/java/com/qualcomm/ftccommon/SoundPlayer.java @@ -34,10 +34,13 @@ are permitted (subject to the limitations in the disclaimer below) provided that import android.content.Context; import android.content.SharedPreferences; +import android.content.res.AssetFileDescriptor; +import android.media.AudioAttributes; import android.media.AudioManager; import android.media.MediaPlayer; import android.media.SoundPool; import android.net.Uri; +import android.os.Build; import android.preference.PreferenceManager; import android.support.annotation.CheckResult; import android.support.annotation.Nullable; @@ -125,6 +128,7 @@ public static SoundPlayer getInstance() protected float soundOnVolume = 1.0f; protected float soundOffVolume = 0.0f; protected float masterVolume = 1.0f; + protected MediaPlayer mediaSizer; protected static class CurrentlyPlaying { @@ -155,7 +159,29 @@ protected enum StopWhat { All, Loops } */ public SoundPlayer(int simultaneousStreams, int cacheSize) { - soundPool = new SoundPool(simultaneousStreams, AudioManager.STREAM_MUSIC, /*quality*/0); // can't use SoundPool.Builder on KitKat + mediaSizer = new MediaPlayer(); + if (Build.VERSION.SDK_INT >= 21) + { + AudioAttributes.Builder audioAttributesBuilder = new AudioAttributes.Builder(); + audioAttributesBuilder.setContentType(AudioAttributes.CONTENT_TYPE_SONIFICATION); + AudioAttributes audioAttributes = audioAttributesBuilder.build(); + + SoundPool.Builder soundPoolBuilder = new SoundPool.Builder(); + soundPoolBuilder.setAudioAttributes(audioAttributes); + soundPoolBuilder.setMaxStreams(simultaneousStreams); + soundPool = soundPoolBuilder.build(); + + mediaSizer.setAudioAttributes(audioAttributes); + AudioManager audioManager = (AudioManager)(AppUtil.getDefContext().getSystemService(Context.AUDIO_SERVICE)); + int audioSessionId = audioManager.generateAudioSessionId(); + mediaSizer.setAudioSessionId(audioSessionId); + } + else + { + /** {@link AudioManager#STREAM_NOTIFICATION} might have been a better choice, but we use STREAM_MUSIC because we've always done so; not worth changing */ + soundPool = new SoundPool(simultaneousStreams, AudioManager.STREAM_MUSIC, /*quality*/0); // can't use SoundPool.Builder on KitKat + mediaSizer.setAudioStreamType(AudioManager.STREAM_MUSIC); + } loadedSounds = new LoadedSoundCache(cacheSize); currentlyPlayingSounds = new HashSet<>(); sharedPreferences = PreferenceManager.getDefaultSharedPreferences(AppUtil.getDefContext()); @@ -191,6 +217,10 @@ public void close() scheduledThreadPool.shutdownNow(); ThreadPool.awaitTerminationOrExitApplication(scheduledThreadPool, 3, TimeUnit.SECONDS, "SoundPool", "internal error"); } + if (mediaSizer != null) + { + mediaSizer.release(); + } } /** @@ -627,18 +657,43 @@ protected void startPlayingLoadedSound(final SoundInfo soundInfo, @Nullable Play protected int getMsDuration(Context context, @RawRes int resourceId) { - MediaPlayer mediaPlayer = MediaPlayer.create(context, resourceId); - int msDuration = mediaPlayer.getDuration(); - mediaPlayer.release(); - return msDuration; + int msDuration = 0; + synchronized (lock) + { + try { + mediaSizer.reset(); + AssetFileDescriptor afd = context.getResources().openRawResourceFd(resourceId); + mediaSizer.setDataSource(afd.getFileDescriptor(), afd.getStartOffset(), afd.getLength()); + afd.close(); + mediaSizer.prepare(); + msDuration = mediaSizer.getDuration(); + } + catch (IOException e) + { + tracer.traceError(e,"exception preparing media sizer; media duration taken to be zero");; + } + } + return msDuration < 0 ? 0 : msDuration; } protected int getMsDuration(Context context, File file) { - MediaPlayer mediaPlayer = MediaPlayer.create(context, Uri.fromFile(file)); - int msDuration = mediaPlayer.getDuration(); - mediaPlayer.release(); - return msDuration; + Uri uri = Uri.fromFile(file); + int msDuration = 0; + synchronized (lock) + { + try { + mediaSizer.reset(); + mediaSizer.setDataSource(context, uri); + mediaSizer.prepare(); + msDuration = mediaSizer.getDuration(); + } + catch (IOException e) + { + tracer.traceError(e,"exception preparing media sizer; media duration taken to be zero");; + } + } + return msDuration < 0 ? 0 : msDuration; } protected void waitForLoadCompletion() diff --git a/library/src/main/java/com/qualcomm/ftccommon/UpdateUI.java b/library/src/main/java/com/qualcomm/ftccommon/UpdateUI.java index 5d55d30..4ecaa20 100644 --- a/library/src/main/java/com/qualcomm/ftccommon/UpdateUI.java +++ b/library/src/main/java/com/qualcomm/ftccommon/UpdateUI.java @@ -203,9 +203,9 @@ void refreshNetworkStatus() { final String message = String.format(format, strNetworkStatus, strPeerStatus); // Log if changed - if (DEBUG || !message.equals(UpdateUI.this.networkStatusMessage)) RobotLog.v(message); - UpdateUI.this.networkStatusMessage = message; + if (!message.equals(UpdateUI.this.networkStatusMessage)) RobotLog.vv(TAG, message); + UpdateUI.this.networkStatusMessage = message; activity.runOnUiThread(new Runnable() { @Override public void run() { @@ -295,6 +295,7 @@ String trimTextErrorMessage(String message) { //------------------------------------------------------------------------------------------------ public static final boolean DEBUG = false; + private static final String TAG = "UpdateUI"; private static final int NUM_GAMEPADS = 2; protected TextView textDeviceName; diff --git a/library/src/main/res/raw/chimeconnect.wav b/library/src/main/res/raw/chimeconnect.wav index 9493a72..6f5a58a 100644 Binary files a/library/src/main/res/raw/chimeconnect.wav and b/library/src/main/res/raw/chimeconnect.wav differ