How to play android motion(Live) photo with MediaPlayer?

175 Views Asked by At

I want to play android motion photo with media player. But I don't want to use mediaPlayer.setDataSource(fileDescriptor, offset, length). Because I am not getting offset for Huawei device's Motion Photo. How can I get the offset for all device's motion photo or is it possible to use mediaPlayer.setDataSource(path, headers) instead? I have heard about a header called 'ftypmp42'. How to use this in this case?

1

There are 1 best solutions below

0
On

You may refer this , i have Done something I may Tell you that may help you to Find the Offset and play

    XmpUtil xmp = new XmpUtil();
    XMPMeta meta = xmp.extractOrCreateXMPMeta(jpegFile.getAbsolutePath());
    haveVideoValue = meta.getProperty("http://ns.google.com/photos/1.0/camera/","GCamera:MicroVideo");
offset=meta.getProperty("http://ns.google.com/photos/1.0/camera/","GCamera:MicroVideoOffset");

//To play the Video with Media player

 FileInputStream inputStream = new FileInputStream(filePath);
                        MediaPlayer mp = new MediaPlayer();

                        mp.setDataSource(inputStream.getFD(), finalJpegFile.length() - Long.valueOf(finalOffset1), Long.valueOf(finalOffset1));
                        mp.prepare();
                        inputStream.close();
                         mp.setDisplay(surface.getHolder());
                        mp.setLooping(true);
                        mp.start();

Credit :- https://medium.com/android-news/working-with-motion-photos-da0aa49b50c