मैं एक वीडियो फ़ाइल डाउनलोड करने की कोशिश कर रहा हूं और फिर इसे ऐप में चला रहा हूं, अगर मैं वीडियो फ़ाइल को res फ़ोल्डर में डालता हूं तो मैं बिना किसी समस्या के इसे चलाने में सक्षम हूं हालांकि, जब मैं वीडियो को आजमाकर डाउनलोड करता हूं तो इसे चलाता हूं मुझे वीडियोव्यू त्रुटि मिलती है: 1, -2147483648।डाउनलोड किए गए वीडियो को चलाने में त्रुटि: 1, -2147483648
try
{
URL url = new URL(videoURL);
URLConnection conexion = url.openConnection();
conexion.connect();
int lengthOfFile = conexion.getContentLength();
Log.d("ANDRO_ASYNC", "Length of file: " + lengthOfFile);
InputStream input = new BufferedInputStream(url.openStream());
final File dir = new File(this.getFilesDir() + "/videos");
dir.mkdirs(); //create folders where write files
final File file = new File(dir, "my_video.mp4");
Log.d("writePath", file.getPath());
FileOutputStream output = new FileOutputStream(file);
byte data[] = new byte[1024];
long total = 0;
while((count = input.read(data)) != -1)
{
total += count;
//publishProgress("" + (int)((total*100)/lengthOfFile));
output.write(data, 0, count);
}
output.flush();
output.close();
input.close();
Log.d("download", "finished");
}
catch(Exception e)
{
Log.d("Exception", e.getMessage());
}
यह सफलतापूर्वक पूर्ण करने के लिए प्रकट होता है, लेकिन जब मैं पीछा किया कोड के साथ फ़ाइल को चलाने का प्रयास, मैं त्रुटि मिलती है:
इस कोड मैं वीडियो डाउनलोड करने के लिए इस्तेमाल करते हैं।
// Play Video
videoView = (VideoView)findViewById(R.id.surface_view);
//
File f = new File("/data/data/com.companyname.appname/files/videos/videoFilename.mp4");
if(f.exists())
{
long len = f.length();
String length = String.valueOf(len);
Log.d("file", "exists");
Log.d("length", (String)length);
}
else
{
Log.d("file", "does not exist");
}
//
videoView.setMediaController(new MediaController(this));
videoView.setVideoPath(f.getPath());
videoView.start();
के रूप में, कोड में देखा खेलने मैं जाँच लें कि फ़ाइल मौजूद है और यह भी आकार से पहले (यह डाउनलोड की गई फ़ाइल के रूप में एक ही आकार है), लेकिन यह नहीं खेलेंगे, मेरा अनुमान है कि फाइल है दूषित लेकिन मुझे नहीं पता क्यों।
मैं निम्न अनुमतियों प्रकट
<uses-permission android:name="android.permission.INTERNET"/>
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE"/>
<uses-permission android:name="android.permission.WRITE_INTERAL_STORAGE" />
मुझे एक ही समस्या मिली। कोई उत्तर ? –
क्या आप अपना पूरा स्टैकट्रैक पोस्ट कर सकते हैं? भी, क्या आपने चेक किया था (चेकसम और आकार या कुछ के साथ) कि आपकी फ़ाइल मान्य है (डाउनलोड भाग में कुछ गड़बड़ हो सकती है)? – njzk2
एक बड़ी फ़ाइल डाउनलोड करने के लिए शायद अधिक मजबूत विधि की आवश्यकता होती है, जैसे कि भाग में डाउनलोड करना। – mparaz