java


Can't resume AudioTrack after pause


I am currently using AudioTrack in stream mode to play some prerecorded tracks. Play and stop mechanics work properly, however when i hit pause and try to resume afterwards one of two outcomes happen:
initialize new buffer and byte array which triggers the writing since the start of the file
buffer only reads -1 and nothing its written into the buffer
I tried to mark and reset the Inputstream, like it's suggested in some posts but it didn't help.
public void pauseTrack() {
currentAudioTrack.pause();
isPaused = true;
}
public void resumeTrack() {
isPaused = false;
}
#Override public void run() {
try {
while (offset < audioFile.length()) {
if (isPaused)
continue;
currentAudioTrack.play();
int numberOfBytesRead = fileInputStream.read(audioData);
if (numberOfBytesRead != -1) {
currentAudioTrack.write(audioData, 0, numberOfBytesRead);
offset+=numberOfBytesRead;
}
else {
return;
}
}
Log.v("status", "finished reading");
} catch (IOException io) {
Log.v("Exception", "IOException found: " + io.getLocalizedMessage());
} catch (IllegalStateException ie) {
Log.v("Exception","IllegalStateException:" + ie.getLocalizedMessage());
}
}
What am i doing wrong? I appreciate some guidance in the matter.
Try this
public void pauseTrack()
{
currentAudioTrack.pause();
isPaused = true;
}
public void resumeTrack()
{
isPaused = false;
}
#Override public void run()
{
try {
while (offset < audioFile.length())
{
if(isPaused != true)
{
currentAudioTrack.play();
int numberOfBytesRead = fileInputStream.read(audioData);
if (numberOfBytesRead != -1) {
currentAudioTrack.write(audioData, 0, numberOfBytesRead);
offset+=numberOfBytesRead;
}
else {
return;
}
}
}
Log.v("status", "finished reading");
} catch (IOException io) {
Log.v("Exception", "IOException found: " + io.getLocalizedMessage());
} catch (IllegalStateException ie) {
Log.v("Exception","IllegalStateException:" + ie.getLocalizedMessage());
}
}

Related Links

How to call a method in an Activity from another class
How to make WordCount use new Java libraries in Cloudera?
Trying to get the code to check if there are even brackets
Java: Incompatible types: ArrayList<Integer> cannot be converted to int
Why does object not delete itself but continue rendering (Java)
Selenium RemoteWebDriver FileDetector Java
Trying to POST data from my android application to a php file on a server but data is always null. Why
Error Input too large for RSA cipher on Android 5.0
Android app button not working
Java: What is the use for ArrayList<ArrayList<Integer>>?
Basic Calculator Help Java
Android - NullPointerException in Fragment after callback
Gson conversion to Json with two date format is not working
Export a JSON sub-node without creating a new class?
How to display today date list and upcoming date list using cardview in android
Delete entry from HashMap [duplicate]

Categories

HOME
yii2
arduino-uno
hook
smarty
webstorm
google-docs
leon
ravendb
applepay
medical
communication
spring-xd
wheelnav.js
imacros
circular-dependency
decimal
serverless-framework
vaadin7
highlight.js
facebook-page
evopdf
csrf-protection
language-agnostic
claims-based-identity
trading
opennlp
shopware
apache-commons-io
pingfederate
publish
skia
sql-server-2012-express
stormpath
bower-install
scaffold
starteam
c11
impersonation
core-plot
elmah
checkboxlist
acoustics
wso2carbon
filepicker
apache-fop
sqlclient
sqlbulkcopy
flutterwave
account-kit
gridpane
libpng
android-textview
wapiti
historian
iad
teamcity-8.0
marching-cubes
map-projections
proj4js
formatjs
has-many-through
starcluster
reactfx
undefined-reference
datagridviewcolumn
concurrent-collections
cloud-connect
flexmojos
html4
chronoforms
datawindow
regsvr32
dotnethighcharts
pendrive
hgsubversion
subgurim-maps
appender
floating
createwindow
filtered-index
temporal-database
sector
defensive-programming
grid-system
dbisam
3gp

Resources

Mobile Apps Dev
Database Users
javascript
java
csharp
php
android
MS Developer
developer works
python
ios
c
html
jquery
RDBMS discuss
Cloud Virtualization
Database Dev&Adm
javascript
java
csharp
php
python
android
jquery
ruby
ios
html
Mobile App
Mobile App
Mobile App