I want to pass the SurfaceView from activity to service using AIDL. In Service I will be rendering the video.
4 Answers
Found the solution, Instead of passing surface view application can pass the Surface which actually implements parcelable interface and instance of Surface class can be passed to MediaPlayer.setSurface() to render the Video.
In .aidl file
import android.view.Surface;
oneway interface{
void startRender( in Surface surface)
}
in Service
MediaPlayer mediaPlayer = new MediaPlayer();
mediaPlayer.stop();
mediaPlayer.reset();
mediaPlayer.setSurface(surfaceViewId);
In application
serviceInstance.startRender((((SurfaceView)findViewById(R.id.surfaceView)).getHolder()).getSurface());

- 12,700
- 3
- 19
- 44
Only one solution is there, But you need to use singleton surfaceview and make sure you don't have any UI leaks in your implmentation. And one thing, you need to reinitialize everytime whereever you use surfaceview. Whenever you move out from activity and service where surfaceview already got initialized will get destroyed. Because surfaceview/surface taken by windowmanager.

- 10,281
- 11
- 57
- 84
You cannot pass surfaceview using AIDL . Only certain data types,list and map are supported by default. You can also parcel custom objects but surfaceview is not one of them. More Info.

- 8,449
- 9
- 37
- 50
-
How can I achieve rendering video in background apart from passing surface view ? – kiran Biradar May 14 '18 at 10:16
Service
in android is designed to do something in background. If you want to play a video file or stream, use a full screen activity with a VideoView
in its layout. Pass the uri of media to VideoView
.

- 8,804
- 8
- 56
- 106