MediaPlayer Streaming issues on Android 4.4 (API 19) - android-mediaplayer

My app is having issues with the MediaPlayer streaming, specifically on Nexus 5. I'm not sure if this is Nexus 5 or API level 19 causing the problem. Basically my MediaPlayer gets prepared and I call MediaPlayer.start(), but the MediaPlayer doesn't begin streaming.
This happens at random and only on my Nexus 5 device. When this happens, if I try seeking the MediaPlayer it begins to play. Is anyone else experiencing this?
UPDATE: I've filed a bug against Android: https://code.google.com/p/android/issues/detail?id=62304

Not sure if it's related, I had similar issue with local file playback, only on 4.4 occasionally, not reproducible on 4.3. This only happens when I want to play a new song reusing the existing MediaPlayer.
Solution: I had to call stop(); before reset(); and setDataSource():
stop();
reset();
try {
setDataSource(context, uri);
prepareAsync();
} catch (IllegalArgumentException e) {
e.printStackTrace();
} catch (SecurityException e) {
e.printStackTrace();
} catch (IllegalStateException e) {
e.printStackTrace();
} catch (IOException e) {
e.printStackTrace();
}

time solution:
in onprepare
before start try this code:
if (mSeekWhenPrepared != 0) {
seekTo(mSeekWhenPrepared);
} else {seekTo(0);}

Related

What does timeout operator measure in Reactor and why it doesn't work in some cases?

Recently, a reactive piece of code results in timeout, it involves redis operation, like this:
redisOps.entries(key).map(...).map(...).switchIfEmpty().timeout();
In order to identify if timeout happens in redis query, I think timeout should be located after entries, in this way, map consumed time would not be monitored by timeout. So I made a guess, and wrote demo.
does timeout monitor data emission elapsed time until it, and data operations after it is not counted? For example, in the following code snippet, only time consumption in a and b are monitored by timeout, not including c or d.
Mono mono = foo();
mono.a().b().timeout().c().d();
Why in the following code, timeout does not work.
Mono.just("good luck")
.map(s -> {
try {
TimeUnit.SECONDS.sleep(1);
} catch (InterruptedException e) {
e.printStackTrace();
}
return "timeout 1";
})
.map(s->{
try {
TimeUnit.SECONDS.sleep(1);
} catch (InterruptedException e) {
e.printStackTrace();
}
return "timeout 2";
})
.timeout(Duration.ofSeconds(1))
.subscribe(System.out::println);
compared with item 2, timeout in the following code works:
public static void main(String[] args) {
Mono.fromCallable(() -> {
log.info("begin 1");
try {
TimeUnit.SECONDS.sleep(2);
} catch (InterruptedException e) {
e.printStackTrace();
}
log.info("return 1");
return "good luck 1";
})
.timeout(Duration.ofMillis(1500l))
.map((s) -> {
log.info("begin 2");
try {
TimeUnit.SECONDS.sleep(1);
} catch (InterruptedException e) {
e.printStackTrace();
}
log.info("return 2");
return "good luck 2";
})
.subscribe(System.out::println);
}
Anwser the comment's question, some operator is eager, it will execute at assembly stage. you can use some lazy operator, eg: defer、fromSupplier...
public Mono<?> defaultData() {
return Mono.defer(() -> {
//do Something
return ...
});
}
Here are some demo(https://github.com/echooymxq/reactive-study).

Intellj recognizing .wav files as plain text

https://i.stack.imgur.com/2IIvj.png
So I'm trying play a sound everytime a letter is typed on screen. The code is definately correct since I copied it from a reliable source online. The only problem is I keep getting the (The system cannot find the path specified) error. Intellij recognizes .wav files as plain text for some reason. Is there a fix to this? Im I doing something wrong? Nothing I searched for works. Here is the code I use :
private class SoundEffect{
Clip clip;
public void setFile(String path) {
try {
File file = new File(path);
AudioInputStream sound = AudioSystem.getAudioInputStream(file);
clip = AudioSystem.getClip();
clip.open(sound);
} catch (UnsupportedAudioFileException e) {
e.printStackTrace();
} catch (IOException e) {
e.printStackTrace();
} catch (LineUnavailableException e) {
e.printStackTrace();
}
}
public void play(){
clip.setFramePosition(0);
clip.start();
}
}
I am getting the error when I use the setFile method.

Plugin Development: Eclipse hangs when testing plugin

I am new to developing plugins, and was wondering what causes a test plugin to hang when started i.e. Eclipse is unresponsive.
I know that my code is working as I developed a voice recognition plugin to write to the screen what is said and when I open notepad everything I say is printed to notepad.
So I was wondering, am I missing something in the plugin life-cycle that causes the IDE to hang when my plugin is started?
package recognise.handlers;
public class SampleHandler extends AbstractHandler {
public SampleHandler() {
}
/**
* the command has been executed, so extract extract the needed information
* from the application context.
*/
public Object execute(ExecutionEvent event) throws ExecutionException {
boolean finish = false;
IWorkbenchWindow window = HandlerUtil.getActiveWorkbenchWindowChecked(event);
MessageDialog.openInformation(
window.getShell(),
"Recognise",
"Starting Recognition");
TakeInput start = new TakeInput();
//Stage a = new Stage();
//SceneManager scene = new SceneManager();
try {
start.startVoiceRecognition(finish);
//scene.start(a);
} catch (IOException | AWTException e) {
e.printStackTrace();
}
return null;
}
}
Does the start.startVoiceRecognition() need to be threaded?
Thanks in advance and let me know if you would like to see my manifest/activator etc.
Conclusion
Added a job separate to the UI thread
/*
* Start a new job separate to the main thread so the UI will not
* become unresponsive when the plugin has started
*/
public void runVoiceRecognitionJob() {
Job job = new Job("Voice Recognition Job") {
#Override
protected IStatus run(IProgressMonitor monitor) {
TakeInput start = new TakeInput();
try {
start.startVoiceRecognition(true);
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (AWTException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (Exception e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
// use this to open a Shell in the UI thread
return Status.OK_STATUS;
}
};
job.setUser(true);
job.schedule();
}
As shown start.startVoiceRecognition() is running in the UI thread, and it will block the UI thread until it is finished and the app will be unresponsive during that time. So if it is doing a significant amount of work either use a Thread or use an Eclipse Job (which runs work in a background thread managed by Eclipse).
To unblock your UI you have to use Display thread.
/**
* the command has been executed, so extract extract the needed information
* from the application context.
*/
public Object execute(ExecutionEvent event) throws ExecutionException {
Display.getDefault().asyncExec(new Runnable() {
public void run() {
boolean finish = false;
IWorkbenchWindow window = HandlerUtil.getActiveWorkbenchWindowChecked(event);
MessageDialog.openInformation(
window.getShell(),
"Recognise",
"Starting Recognition");
TakeInput start = new TakeInput();
//Stage a = new Stage();
//SceneManager scene = new SceneManager();
try {
start.startVoiceRecognition(finish);
//scene.start(a);
} catch (IOException | AWTException e) {
e.printStackTrace();
}
MessageDialog.openInformation(shell, "Your Popup ",
"Your job has finished.");
}
});
return null;
}
You can use Display.getDefault().asyncExec() as mentioned above, so your UI will be unblocked, while your non UI code will be executing.

Cannot play video *.mp4 in sdCard by SurfaceView android

I have a video .mp4 in sdCard ,If play video by VideoView it play Ok .But if
I use SurfaceView to play this video .I can not play .Please help me .Thank you so much !.This is my code to play video use SurfaceView
String pathVideo = watchIntent.getStringExtra("pathFileVideo");
SurfaceHolder videoHolder = videoSurface.getHolder();
videoHolder.addCallback(this);
mPlayer = new MediaPlayer();
controller = new VideoControllerView(mContext);
try {
mPlayer.setAudioStreamType(AudioManager.STREAM_MUSIC);
mPlayer.setDataSource(pathVideo);
mPlayer.setOnPreparedListener(this);
} catch (IllegalArgumentException e) {
e.printStackTrace();
} catch (SecurityException e) {
e.printStackTrace();
} catch (IllegalStateException e) {
e.printStackTrace();
} catch (IOException e) {
e.printStackTrace();
}

Progress is not shown in Eclipse wizard window

I am developing an Eclipse plugin that creates a project in the current workspace. I want to show a progress bar in the wizard window (above the next - previous - finish buttons ) to represent the progress of creation. However, when the finish button is pressed, the progress bar is not shown. Below is my code.
#Override
WorkspaceModifyOperation op = new WorkspaceModifyOperation() {
#Override
protected void execute(IProgressMonitor monitor) throws CoreException,
InvocationTargetException, InterruptedException {
monitor.beginTask("Create *** Project", 100);
try {
ProjectUtil.createProject(monitor);
} catch (Exception e) {
} finally {
monitor.done();
}
monitor.done();
}
};
try {
getContainer().run(true, true, op);
} catch (InvocationTargetException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (InterruptedException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
Inside the createProject(IProgressMonitor monitor) method of class ProjectUtil, I have monitor.worked(someWork) after each operation.
What am I missing?
Try to set setNeedsProgressMonitor(true); in the class, which extends Wizard. Hope this helps.