Cargar un archivo de almacenamiento externo a Inputstream
Tengo un archivo de vídeo en mi directorio externo. cómo puedo cargarlo en la variable inputstream. Por el momento estoy leyendo el archivo en la carpeta res/raw pero quiero leerlo desde la tarjeta SD. tampoco sé sobre el nombre del archivo, pero su ruta se recibirá a través de intent. compruebe el siguiente código
public class SonicTest extends Activity
{
VideoView videoView;
String uri;
InputStream soundFile;
File file;
@Override
public void onCreate(Bundle savedInstanceState)
{
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
}
public void play(View view)
{
new Thread(new Runnable()
{
public void run()
{
float speed= (float) 1.0;
float pitch= (float) 1.5;
float rate= (float) 1.0;
uri= Environment.getExternalStorageDirectory().toString();
uri=uri+"/video.3gp";
AndroidAudioDevice device = new AndroidAudioDevice(22050, 1);
Sonic sonic = new Sonic(22050, 1);
byte samples[] = new byte[4096];
byte modifiedSamples[] = new byte[2048];
InputStream soundFile = null;
//soundFile = getContentResolver().openInputStream(Uri.parse(uri));
soundFile=getResources().openRawResource(R.raw.video3);
Log.i("testing","check if SoundFile is correct "+soundFile);
int bytesRead;
if(soundFile != null) {
sonic.setSpeed(speed);
sonic.setPitch(pitch);
sonic.setRate(rate);
do {
try {
bytesRead = soundFile.read(samples, 0, samples.length);
} catch (IOException e) {
e.printStackTrace();
return;
}
if(bytesRead > 0) {
sonic.putBytes(samples, bytesRead);
} else {
sonic.flush();
}
int available = sonic.availableBytes();
if(available > 0) {
if(modifiedSamples.length < available) {
modifiedSamples = new byte[available*2];
}
sonic.receiveBytes(modifiedSamples, available);
device.writeSamples(modifiedSamples, available);
}
} while(bytesRead > 0);
device.flush();
}
}
} ).start();
}}
28
Author: Talha Malik, 2013-03-27
3 answers
Intenta
File file = new File(Uri.toString());
FileInputStream fileInputStream = new FileInputStream(file);
Entonces puedes leer de la secuencia.
62
Author: Gabe Sechan,
Warning: date(): Invalid date.timezone value 'Europe/Kyiv', we selected the timezone 'UTC' for now. in /var/www/agent_stack/data/www/ajaxhispano.com/template/agent.layouts/content.php on line 61
2014-01-09 04:24:39
Warning: date(): Invalid date.timezone value 'Europe/Kyiv', we selected the timezone 'UTC' for now. in /var/www/agent_stack/data/www/ajaxhispano.com/template/agent.layouts/content.php on line 61
2014-01-09 04:24:39
String fileName = "OfflineMap/maps.xml";
String path = Environment.getExternalStorageDirectory()+"/"+fileName;
File file = new File(path);
FileInputStream fileInputStream = new FileInputStream(file);
7
Author: Satya,
Warning: date(): Invalid date.timezone value 'Europe/Kyiv', we selected the timezone 'UTC' for now. in /var/www/agent_stack/data/www/ajaxhispano.com/template/agent.layouts/content.php on line 61
2015-01-21 06:19:17
Warning: date(): Invalid date.timezone value 'Europe/Kyiv', we selected the timezone 'UTC' for now. in /var/www/agent_stack/data/www/ajaxhispano.com/template/agent.layouts/content.php on line 61
2015-01-21 06:19:17
soundFile = openFileInput(uri);
0
Author: Mobeen Altaf,
Warning: date(): Invalid date.timezone value 'Europe/Kyiv', we selected the timezone 'UTC' for now. in /var/www/agent_stack/data/www/ajaxhispano.com/template/agent.layouts/content.php on line 61
2014-06-12 11:09:25
Warning: date(): Invalid date.timezone value 'Europe/Kyiv', we selected the timezone 'UTC' for now. in /var/www/agent_stack/data/www/ajaxhispano.com/template/agent.layouts/content.php on line 61
2014-06-12 11:09:25