Vijay
Vijay

Reputation: 435

How can I play a video file on Android Wearable?

Hi I am trying to play a video file on my Android wear. The video file is located in the sdcard folder on the wearable device. But I am unable to play it using my Android application. If i run the same application on my smartphone (Nexus 5), it works.

How can I play a video file on Android Wearable using my android app.

Upvotes: 3

Views: 1092

Answers (2)

A. Steenbergen
A. Steenbergen

Reputation: 3440

Finally I made it work. I don't know if this is something Android Wear specific or a bug, but it turns out that

String path = "android.resource://" + getPackageName() + "/" + R.raw.video_file;
File file = new File(path);

does not give access to the file on Android Wear devices.

Instead one has to convert the file into a temp file first:

InputStream ins = MainActivityBackup.this.getResources().openRawResource (R.raw.hyperlapse2);
File tmpFile = null;
OutputStream output;

try {
    tmpFile = File.createTempFile("video","mov");
    output = new FileOutputStream(tmpFile);

    final byte[] buffer = new byte[102400];
    int read;

    while ((read = ins.read(buffer)) != -1) {
        output.write(buffer, 0, read);
    }
    output.flush();
    output.close();
    ins.close();
} catch (IOException e) {
    e.printStackTrace();
}

And then it can be loaded into a videoView

mVideoView.setVideoPath(tmpFile.getPath());

Provided you are using your own video decoder or a library like ffmpeg or vitamio, since Android Wear does not support native video playback yet.

I implemented vitamio in roughly 5 minutes, if needed it can be imported via gradle dependency (look for it on gradleplease). Built my app around vitamio videoView and it works like a charm. It can even play flash video.

Upvotes: 1

HHK
HHK

Reputation: 5330

Android Wear only includes Audio codecs as of Android Wear 5.0 so the normal MediaPlayer APIs won't work. You need to roll your own using video libraries like ffmpeg, ...

Upvotes: 1

Related Questions