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

Can't load resource from jar
My app start automatically after I cancel it
Where the Local object Will be Stored of String in java
Android Progressive Stream Audio File received in HTTP response Progressive
How to set Vaadin 6 'Select' box select value
how to find client system mac address in web application
I get java code 13 error when i try to run eclipse
where to use ArrayList and where to use simple array specially for integer
hibernate console configuration cant find jdbc driver in database connection
Java API for calculating percent [closed]
How could I apply custom LifecycleStrategySupport to camel context
Size JavaFX WebView to the minimum size needed by the document body
I need help about pass a child as a father in a method [Java]
how to clear console window in java
A * Heuristic for Sliding Puzzle is not working as expected
Every operation returns a Division [duplicate]

Categories

HOME
cakephp
compiler-construction
deployment
keycloak
openstack
hp-exstream
hashmap
objectgears
cvs
windows-server
bs4
android-youtube-api
webrequest
adobe-analytics
nano-server
dax
modelica
collectd
jsprit
google-static-maps
aurigma
normalizr
text-rendering
beyondcompare
nhibernate-envers
openedx
conemu
visjs
clickonce
captiveportal
java-7
url-scheme
maxmind
maquette
saas
wtx
gsoap
android-nestedscrollview
jmonkeyengine
serve
objectlistview
unspecified
opshub
broadcastreceiver
password-encryption
reactive-cocoa-5
logfiles
angular-resource
outlook-2013
xml-documentation
zip4j
theming
alphabet
csound
knpmenubundle
django-scheduler
query-performance
google-cdn
pintos
radtreelist
dstu2-fhir
asp.net-4.5
bstr
hover-over
pickadate
nessus
php-parse-error
goose
vhd
teamcity-8.0
jqgrid-formatter
android-listview
unity5.2.3
tween
file-copying
code-access-security
zend-route
expected-exception
kgdb
balanced-payments
mcts
ora-00911
wsdl-2.0
specification-pattern
bitsharp
eclipse-templates
boost-filesystem
gnu-prolog
heartbeat
xtype
rfc1123
inotifycollectionchanged
firefox-5
audio-capture
microsoft-virtualization
backcolor
scripting-languages
.net-1.0
ajax-forms

Resources

Database Users
RDBMS discuss
Database Dev&Adm
javascript
java
csharp
php
android
javascript
java
csharp
php
python
android
jquery
ruby
ios
html
Mobile App
Mobile App
Mobile App