Dans mon application android j'essaye de créer un fichier de musique en utilisant créer temp et en essayant de lire that.Maintenant je suis capable de créer mais il donne une erreur en disant que la vidéo ne peut pas être jouée.créer un fichier temporaire en android
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
requestWindowFeature(Window.FEATURE_NO_TITLE);
//File newfile=new File("/data/data/com.ayansys.samplevideo/Music.3gp");
//String xyz=newfile.getAbsolutePath();
getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN,WindowManager.LayoutParams.FLAG_FULLSCREEN); // Sets the window in full screen
setContentView(R.layout.main);
// path.g
// Log.i("Raw folder path:", R.raw.music);
String path= musicFile();
try{
Thread.sleep(5000);
}
catch(InterruptedException e)
{
e.printStackTrace();
Log.i("exception raised",e.toString());
}
mVideoView = (VideoView) findViewById(R.id.surface_view);
// mVideoView.setVideoURI(Uri.parse("android.resource://com.ayansys.samplevideo/"+R.raw.music));
// File infile=new File("/data/data/com.ayansys.samplevideo/Video.3gp");
mVideoView.setVideoPath(path);
mVideoView.requestFocus();
mVideoView.start();
}
public String musicFile()
{
String temPath = null;
try{
File outFile=File.createTempFile("music", ".3gp", getDir(temPath, MODE_PRIVATE));
temPath=outFile.getAbsolutePath();
FileOutputStream f=new FileOutputStream(outFile);
//FileOutputStream fos = openFileOutput("music.3gp", Context.MODE_PRIVATE);
URL u = new URL("http://59.162.166.211/aptv-web/VODAFONE/STARONE/SarabhaivsSarabhai/J2ME/SarabhaivsSarabhai_05.3gp");
HttpURLConnection c = (HttpURLConnection) u.openConnection();
c.setRequestMethod("GET");
c.setDoOutput(true);
c.connect();
//FileOutputStream f = new FileOutputStream(new File("/sdcard/videooutput.mp4"));
InputStream in = c.getInputStream();
byte[] buffer = new byte[1024];
int len1 = 0;
while ((len1 = in.read(buffer))!= -1) {
f.write(buffer,0,len1);
}
f.close();
String str=outFile.getAbsolutePath();
//outFile..close();
in.close();
}
catch(Exception e)
{
e.printStackTrace();
System.out.println("Exception raised in creating a file: "+e.toString());
}
return temPath;
}
}
Je voudrais jouer ce. S'il vous plaît partagez vos précieuses suggestions.
Merci à l'avance
Ce problème a déjà été résolu. [stackoverflow] [1] [1]: http://stackoverflow.com/a/6485850/967548 –