Cannot play video *.mp4 in sdCard by SurfaceView android - android-mediaplayer

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();
}

Related

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.

IOException Error on Putting Uri Source In Media Player (setDataSource)

Getting an IOException Error While Putting Uri Source Into An Object Of MediaPlayer Using setDataSource. Trying To Get Uri Of A Song From Mobile Using
Intent intent = new Intent(Intent.ACTION_PICK, android.provider.MediaStore.Audio.Media.EXTERNAL_CONTENT_URI);
startActivityForResult(intent, 10);
onActivityResult
#Override
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
if(resultCode == RESULT_OK && requestCode == 10){
Uri uriSound=data.getData();
Toast.makeText(getApplicationContext(),"It Came Here",Toast.LENGTH_SHORT).show();
play_sound(uriSound);
}
}
play_sound
private void play_sound( Uri uri) {
Toast.makeText(getApplicationContext(),"It Came Here 2" + uri,Toast.LENGTH_LONG).show();
MediaPlayer mp = new MediaPlayer();
try {
mp.setDataSource(getApplicationContext(), uri);
mp.start();
} catch (IllegalArgumentException e) {
Toast.makeText(getApplicationContext(),"Error 1",Toast.LENGTH_LONG).show();
e.printStackTrace();
} catch (SecurityException e) {
Toast.makeText(getApplicationContext(),"Error 2",Toast.LENGTH_LONG).show();
e.printStackTrace();
} catch (IllegalStateException e) {
Toast.makeText(getApplicationContext(),"Error 3",Toast.LENGTH_LONG).show();
e.printStackTrace();
} catch (IOException e) {
Toast.makeText(getApplicationContext(),"Error 4",Toast.LENGTH_LONG).show();
e.printStackTrace();
}
}
I Used Toast To Check Where Is Error .
Getting Error In "IOException e" I Dont Know What Is It On Googling It All I Get Is That It Is SOme Kind Of " File Format" Issue Of Selected File.
Solved!! By Just Adding One Line In Play Sound
mP.setAudioStreamType(AudioManager.STREAM_MUSIC);
Play_Sound(Uri uri) :
private void Play_Sound(Uri uri)
{
MediaPlayer mPlayer = new MediaPlayer();
mPlayer.setAudioStreamType(AudioManager.STREAM_MUSIC);
try {
mPlayer.setDataSource(getApplicationContext(), uri);
} catch (IllegalArgumentException e) {
Toast.makeText(getApplicationContext(), "You might 1 not set the URI correctly!", Toast.LENGTH_LONG).show();
} catch (SecurityException e) {
Toast.makeText(getApplicationContext(), "You might 2 not set the URI correctly!", Toast.LENGTH_LONG).show();
} catch (IllegalStateException e) {
Toast.makeText(getApplicationContext(), "You might 3 not set the URI correctly!", Toast.LENGTH_LONG).show();
} catch (IOException e) {
Toast.makeText(getApplicationContext(), "You might 4 not set the URI correctly!", Toast.LENGTH_LONG).show();
e.printStackTrace();
}
try {
mPlayer.prepare();
} catch (IllegalStateException e) {
Toast.makeText(getApplicationContext(), "You might not set the URI correctly!", Toast.LENGTH_LONG).show();
} catch (IOException e) {
Toast.makeText(getApplicationContext(), "You might not set the URI correctly!", Toast.LENGTH_LONG).show();
}
mPlayer.start();
}

MediaPlayer Streaming issues on Android 4.4 (API 19)

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);}

Adding directory to classpath in IntelliJ 12

I know this has been addressed before here but this solution doesn't work for me, and I don't know why.
I follow the given steps, but at 5 there is no dialog that comes up. I am trying to add mp3plugin.jar to my dependencies, but after following this process, I still get an UnsupportedAudioFileException at runtime.
What am I doing wrong?
Here is a screencast of what I am doing: http://www.screenr.com/G70H
Here is the code that uses the audio file:
import javax.sound.sampled.*;
import java.io.File;
import java.io.IOException;
public class Sound {
private Clip clip;
public Sound (String in){
try{
File file = new File ("src/music/" + in + ".mp3");
//System.out.println(file.getAbsolutePath());
clip = AudioSystem.getClip();
AudioInputStream inputStream = AudioSystem.getAudioInputStream(file);
clip.open(inputStream);
} catch (IOException e){
e.printStackTrace();
} catch (LineUnavailableException e){
e.printStackTrace();
} catch (UnsupportedAudioFileException e){
e.printStackTrace();
}
}
public void stop(){
clip.stop();
}
public void loop(){
if (!clip.isActive()){
clip.setFramePosition(0);
clip.loop(Clip.LOOP_CONTINUOUSLY);
} else {
System.out.println("already playing..");
}
}
}
And in this runs it:
Sound sound = new Sound (in.readLine()); //from a bufferedreader
sound.loop();
I know this works because it works with .wav files.

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.