Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
51 changes: 43 additions & 8 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,14 +1,34 @@
# This .gitignore file should be placed at the root of your Unity project directory
#
# Get latest from https://github.com/github/gitignore/blob/master/Unity.gitignore
#
/[Ll]ibrary/
/[Tt]emp/
/[Oo]bj/
/[Bb]uild/
/[Bb]uilds/
/Assets/AssetStoreTools*
/.gradle/
/.idea/
/[Ll]ogs/
/[Uu]ser[Ss]ettings/

# Visual Studio 2015 cache directory
/.vs/
# MemoryCaptures can get excessive in size.
# They also could contain extremely sensitive data
/[Mm]emoryCaptures/

# Asset meta data should only be ignored when the corresponding asset is also ignored
!/[Aa]ssets/**/*.meta

# Uncomment this line if you wish to ignore the asset store tools plugin
# /[Aa]ssets/AssetStoreTools*

# Autogenerated Jetbrains Rider plugin
/[Aa]ssets/Plugins/Editor/JetBrains*

# Visual Studio cache directory
.vs/
.vscode/

# Gradle cache directory
.gradle/

# Autogenerated VS/MD/Consulo solution and project files
ExportedObj/
Expand All @@ -24,14 +44,29 @@ ExportedObj/
*.booproj
*.svd
*.pdb
*.mdb
*.opendb
*.VC.db

# Unity3D generated meta files
*.pidb.meta
*.pdb.meta
*.mdb.meta

# Unity3D Generated File On Crash Reports
# Unity3D generated file on crash reports
sysinfo.txt

# Builds
*.apk
/.project
MemoryCaptures
*.aab
*.unitypackage

# Crashlytics generated file
crashlytics-build.properties

# Packed Addressables
/[Aa]ssets/[Aa]ddressable[Aa]ssets[Dd]ata/*/*.bin*

# Temporary auto-generated Android Assets
/[Aa]ssets/[Ss]treamingAssets/aa.meta
/[Aa]ssets/[Ss]treamingAssets/aa/*
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
import android.content.Intent;
import android.content.res.Resources;
import android.media.MediaPlayer;
import android.media.PlaybackParams;
import android.net.Uri;
import android.os.Build;
import android.os.IBinder;
Expand Down Expand Up @@ -37,6 +38,7 @@ public class BackgroundAudioService extends Service {
private static final String EXTRA_INSTANCE_ID = "instanceId";
private static final String EXTRA_VOLUME = "volume";
private static final String EXTRA_LOOP = "loop";
private static final String EXTRA_SPEED = "speed";

private static final String ACTION_SET_VOLUME = "volume";
private static final String ACTION_SET_LOOP = "loop";
Expand All @@ -47,6 +49,7 @@ public class BackgroundAudioService extends Service {
private static final String ACTION_RESUME = "resume";
private static final String ACTION_SEEK = "seek";
private static final String ACTION_STOP_SERVICE = "stopService";
private static final String ACTION_SET_SPEED = "speed";

private static final String TAG = "BackgroundAudio";
private volatile static HashMap<Integer, MediaWrapper> usedMediaPlayers = new HashMap<>();
Expand Down Expand Up @@ -239,6 +242,23 @@ public int onStartCommand(Intent intent, int flags, int startId) {
serviceActive = false;
stopSelf();

break;
}
case ACTION_SET_SPEED:{
if (!usedMediaPlayers.containsKey(instanceId)) break;
MediaWrapper wrapper = usedMediaPlayers.get(instanceId);

float speed = intent.getFloatExtra(EXTRA_SPEED, 1f);

try {
PlaybackParams params = wrapper.player.getPlaybackParams();
params.setSpeed(speed);
wrapper.player.setPlaybackParams(params);
} catch (Exception e) {
Log.d(TAG, e.getMessage());
throw e;
}

break;
}
}
Expand Down Expand Up @@ -407,8 +427,17 @@ public static void setLoop(Context context, int id, boolean value) {
context.startService(intent);
}

private static void setSpeed(Context context, int id, float speed) {
Intent intent = new Intent(context, BackgroundAudioService.class);
intent.putExtra(EXTRA_INSTANCE_ID, id);
intent.setAction(ACTION_SET_SPEED);
intent.putExtra(EXTRA_SPEED, speed);

context.startService(intent);
}

@Override
public IBinder onBind(Intent intent) {
return null;
}
}
}
2 changes: 2 additions & 0 deletions Assets/BackgroundAudio/Plugins/Android/MediaWrapper.java
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ public class MediaWrapper {
public MediaPlayer player;
public int instanceId;
public boolean playing, paused;
public float speed;

public MediaWrapper(int instanceId) {
this.player = new MediaPlayer();
Expand All @@ -17,5 +18,6 @@ public void Reset(){
this.player.reset();
this.playing = false;
this.paused = false;
this.speed = 1;
}
}
71 changes: 70 additions & 1 deletion Assets/BackgroundAudio/Plugins/Android/MediaWrapper.java.meta

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 0 additions & 1 deletion Assets/BackgroundAudio/Plugins/iOS/AudioInstance.swift
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,6 @@ class AudioInstance: AVAudioPlayer, AVAudioPlayerDelegate {
print("\(#function) called on an audioplayer with no InstanceId");
return;
}

UnityBackgroundAudio.dispose(instanceId: instanceId);
}
}

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

7 changes: 4 additions & 3 deletions Assets/BackgroundAudio/Plugins/iOS/UnityBackgroundAudio.mm
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@

#import <Foundation/Foundation.h>
#import <AVFoundation/AVFoundation.h>
// This header file is generated automatically when Xcode build runs.
#import "unityswift-Swift.h" // Required
#import "UnityFramework/UnityFramework-Swift.h"

extern "C" {

Expand Down Expand Up @@ -46,6 +44,9 @@ void _setLoop(const int identifier, const bool value) {
[UnityBackgroundAudio setLoopForInstanceId:identifier to:value];
}

void _setSpeed(const int identifier, const float speed){
[UnityBackgroundAudio setSpeedForInstanceId:identifier to:speed];
}

bool _isLooping(const int identifier) {
return [UnityBackgroundAudio isLoopingOnInstanceId:identifier];
Expand Down

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading