Wednesday, June 29, 2011

[android-developers] Re: Vedio Chunks is not acessible

You can't just split the file like you did there. Files need metadata,
codec requires the first frame to be a keyframe(or something similar)
and so on.
I doubt that the resulting files that you get can be even played by a
desktop media player...

You just have to research how to split up media files properly.
Because you can't do it like you did it.

On Jun 28, 10:27 am, suresh sharma <sureshsharma...@gmail.com> wrote:
> Thanks for the Previous satisfactory answers.Now i m working in
> Android division & challenge is now to play vedio file from sdcard.it
> sounds easy.But Obstacle is File is >300 MB (like 1 GB). Android
> sdcard accessing doesn't support >300 MB. So I decided to derive the
> Vedio in Smaller Chunks. My code is as below.But Error is, Vedio can't
> be played.please have a look & also see the DDMS CatLog at last.
> **CODE:**
>
> public class VideoViewDemo extends Activity {
>         private static final String TAG = "VideoViewDemo";
>
>         private VideoView mVideoView;
>         private EditText mPath;
>         private ImageButton mPlay;
>         private ImageButton mPause;
>         private ImageButton mReset;
>         private ImageButton mStop;
>         private String current;
>
>         @Override
>         public void onCreate(Bundle icicle) {
>                 super.onCreate(icicle);
>                 setContentView(R.layout.main);
>                 mVideoView = (VideoView) findViewById(R.id.surface_view);
>
>                 mPath = (EditText) findViewById(R.id.path);
>                 mPath.setText("sdcard/E0010023.mp4");
>
>                 mPlay = (ImageButton) findViewById(R.id.play);
>                 mPause = (ImageButton) findViewById(R.id.pause);
>                 mReset = (ImageButton) findViewById(R.id.reset);
>                 mStop = (ImageButton) findViewById(R.id.stop);
>
>                 mPlay.setOnClickListener(new OnClickListener() {
>                         public void onClick(View view) {
>                                 playVideo();
>                         }
>                 });
>                 mPause.setOnClickListener(new OnClickListener() {
>                         public void onClick(View view) {
>                                 if (mVideoView != null) {
>                                         mVideoView.pause();
>                                 }
>                         }
>                 });
>                 mReset.setOnClickListener(new OnClickListener() {
>                         public void onClick(View view) {
>                                 if (mVideoView != null) {
>                                         mVideoView.seekTo(0);
>                                 }
>                         }
>                 });
>                 mStop.setOnClickListener(new OnClickListener() {
>                         public void onClick(View view) {
>                                 if (mVideoView != null) {
>                                         current = null;
>                                         mVideoView.stopPlayback();
>                                 }
>                         }
>                 });
>                 runOnUiThread(new Runnable(){
>                         public void run() {
>                                 playVideo();
>
>                         }
>
>                 });
>         }
>
>         private void playVideo() {
>                 try {
>                         final String path = mPath.getText().toString();
>                         Log.v(TAG, "path: " + path);
>                         if (path == null || path.length() == 0) {
>                                 Toast.makeText(VideoViewDemo.this, "File URL/path is empty",
>                                                 Toast.LENGTH_LONG).show();
>
>                         } else {
>                                 // If the path has not changed, just start the media player
>                                 if (path.equals(current) && mVideoView != null) {
>                                         mVideoView.start();
>                                         mVideoView.requestFocus();
>                                         return;
>                                 }
>                                 current = path;
>
>                                 int chunkCount=0;
>
>                                 for(int i=0;i<numberOfChunks:i++)
> {
>                                 mVideoView.setVideoPath(getDataSource( "/sdcard/"+mRecordingFile +
> "." + i));
>
> }
>
>                                 mVideoView.setOnTouchListener(new View.OnTouchListener() {
>
>                                         public boolean onTouch(View v, MotionEvent event) {
>                                             int width = mVideoView.getMeasuredWidth();
>                                             int height = mVideoView.getMeasuredHeight();
>                                             //we add 10 pixels to the current size of the video view
> every time you touch
>                                             //the media controller.
>                                             LayoutParams params = new LinearLayout.LayoutParams(width+10,
> height+10);
>                                             mVideoView.setLayoutParams(params);
>
>                                             return true;
>                                         }
>
>                                         });
>
>                                 mVideoView.start();
>                                 mVideoView.requestFocus();
>
>                         }
>                 } catch (Exception e) {
>                         Log.e(TAG, "error: " + e.getMessage(), e);
>                         if (mVideoView != null) {
>                                 mVideoView.stopPlayback();
>                         }
>                 }
>         }
>
>         private String getDataSource(String path) throws IOException {
>                 if (!URLUtil.isNetworkUrl(path)) {
>                         return path;
>                 } else {
>                         URL url = new URL(path);
>                         URLConnection cn = url.openConnection();
>                         cn.connect();
>                         InputStream stream = cn.getInputStream();
>                         if (stream == null)
>                                 throw new RuntimeException("stream is null");
>                         File temp = File.createTempFile("mediaplayertmp", "dat");
>                         temp.deleteOnExit();
>                         String tempPath = temp.getAbsolutePath();
>                         FileOutputStream out = new FileOutputStream(temp);
>                         byte buf[] = new byte[128];
>                         do {
>                                 int numread = stream.read(buf);
>                                 if (numread <= 0)
>                                         break;
>                                 out.write(buf, 0, numread);
>                         } while (true);
>                         try {
>                                 stream.close();
>                         } catch (IOException ex) {
>                                 Log.e(TAG, "error: " + ex.getMessage(), ex);
>                         }
>                         getBytesFromFile(temp);
>                         return tempPath;
>                 }
>         }
>
>         /////////////////////////Code for making
> Chunks  ////////////////////////
>
>         String mRecordingFile;
>
>         private void getBytesFromFile(File file) throws IOException {
>             FileInputStream is = new FileInputStream(file); //videorecorder
> stores video to file
>
>             java.nio.channels.FileChannel fc = is.getChannel();
>             java.nio.ByteBuffer bb = java.nio.ByteBuffer.allocate(10485760);
>
>             int chunkCount = 0;
>
>             byte[] bytes;
>
>             while(fc.read(bb) >= 0){
>                 bb.flip();
>                 //save the part of the file into a chunk
>                 bytes = bb.array();
>                 storeByteArrayToFile(bytes, "/sdcard/"+mRecordingFile + "." +
> chunkCount);//mRecordingFile is the (String)path to file
>                 chunkCount++;
>                 bb.clear();
>             }
>         }
>
>         private void storeByteArrayToFile(byte[] bytesToSave, String path)
> throws IOException {
>             FileOutputStream fOut = new FileOutputStream(path);
>             try {
>                 fOut.write(bytesToSave);
>             }
>             catch (Exception ex) {
>                 Log.e("ERROR", ex.getMessage());
>             }
>             finally {
>                 fOut.close();
>             }
>         }
>
> }
>
> **DDMS CatLog is**
>
> 06-28 12:31:49.321: VERBOSE/VideoViewDemo(3812): path: sdcard/
> E0010023.mp4
> 06-28 12:31:49.580: INFO/StagefrightPlayer(34): setDataSource('/sdcard/
> null.0')
> 06-28 12:31:49.632: INFO/ActivityManager(79): Displayed activity
> org.apache.android.media/.VideoViewDemo: 1112 ms (total 1112 ms)
> 06-28 12:31:49.664: ERROR/MediaPlayer(3812): error (1, -2147483648)
> 06-28 12:31:49.720: ERROR/MediaPlayer(3812): Error (1,-2147483648)
> 06-28 12:31:49.720: DEBUG/VideoView(3812): Error: 1,-2147483648
> 06-28 12:31:55.450: DEBUG/dalvikvm(2174): GC_EXPLICIT freed 170
> objects / 11992 bytes in 126ms
> 06-28 12:32:05.200: DEBUG/dalvikvm(2189): GC_EXPLICIT freed 700
> objects / 38792 bytes in 126ms
> 06-28 12:32:10.281: DEBUG/dalvikvm(2199): GC_EXPLICIT freed 44
> objects / 2088 bytes in 162ms
> 06-28 12:32:25.452: WARN/InputManagerService(79): Window already
> focused, ignoring focus gain of:
> com.android.internal.view.IInputMethodClient$Stub$Proxy@45107dd8
> 06-28 12:35:34.713: DEBUG/SntpClient(79): request time failed:
> java.net.SocketException: Address family not supported by protocol
> 06-28 12:40:34.779: DEBUG/SntpClient(79): request time failed:
> java.net.SocketException: Address family not supported by protocol
> 06-28 12:45:34.803: DEBUG/SntpClient(79): request time failed:
> java.net.SocketException: Address family not supported by protocol

--
You received this message because you are subscribed to the Google
Groups "Android Developers" group.
To post to this group, send email to android-developers@googlegroups.com
To unsubscribe from this group, send email to
android-developers+unsubscribe@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/android-developers?hl=en

No comments:

Post a Comment