Skip to content

Commit

Permalink
Add TimedText demo & Video buffer demo
Browse files Browse the repository at this point in the history
  • Loading branch information
Crossle Song committed Aug 13, 2013
1 parent d3e183b commit 7920cb2
Show file tree
Hide file tree
Showing 12 changed files with 570 additions and 4 deletions.
27 changes: 24 additions & 3 deletions vitamio-sample/AndroidManifest.xml
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="io.vov.vitamio.demo"
android:versionCode="2"
android:versionName="0.0." >
android:versionCode="002"
android:versionName="0.0.2" >

<uses-sdk
android:minSdkVersion="14"
android:targetSdkVersion="17" />
android:targetSdkVersion="18" />

<uses-permission android:name="android.permission.WAKE_LOCK" />
<uses-permission android:name="android.permission.INTERNET" />
Expand Down Expand Up @@ -52,6 +52,27 @@
android:name=".MediaMetadataRetrieverDemo"
android:label="Media/MediaMetadata" >
</activity>
<activity
android:name=".VideoSubtitleDemo"
android:label="@string/title_activity_video_subtitle_demo" >
</activity>
<activity
android:name=".MediaPlayerSubtitle"
android:label="@string/title_activity_media_player_subtitle" >
</activity>
<activity
android:name=".VideoViewSubtitle"
android:label="@string/title_activity_video_view_subtitle" >
</activity>
<activity
android:name=".VideoSubtitleList"
android:label="@string/title_activity_video_subtitle_list" >
</activity>
<activity
android:name=".VideoBuffer"
android:label="@string/title_activity_video_buffer" >

</activity>
</application>

</manifest>
2 changes: 1 addition & 1 deletion vitamio-sample/project.properties
Original file line number Diff line number Diff line change
Expand Up @@ -11,5 +11,5 @@
#proguard.config=${sdk.dir}/tools/proguard/proguard-android.txt:proguard-project.txt

# Project target.
target=android-17
target=android-18
android.library.reference.1=../vitamio
21 changes: 21 additions & 0 deletions vitamio-sample/res/layout/subtitle1.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical" >

<SurfaceView android:id="@+id/surface"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_centerHorizontal="true"
android:layout_centerVertical="true"
/>

<TextView android:id="@+id/sub1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@string/res_audio"
android:layout_alignParentBottom="true"
android:layout_centerInParent="true"
/>
</RelativeLayout>
29 changes: 29 additions & 0 deletions vitamio-sample/res/layout/subtitle2.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical" >

<io.vov.vitamio.widget.CenterLayout
android:id="@+id/dd"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical" >

<io.vov.vitamio.widget.VideoView
android:id="@+id/surface_view"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_centerHorizontal="true"
android:layout_centerVertical="true" />
</io.vov.vitamio.widget.CenterLayout>

<TextView
android:id="@+id/subtitle_view"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
android:layout_centerInParent="true"
android:text="@string/res_audio" />

</RelativeLayout>
47 changes: 47 additions & 0 deletions vitamio-sample/res/layout/videobuffer.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical" >

<io.vov.vitamio.widget.CenterLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical" >

<io.vov.vitamio.widget.VideoView
android:id="@+id/buffer"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_centerHorizontal="true"
android:layout_centerVertical="true" />
</io.vov.vitamio.widget.CenterLayout>

<LinearLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerInParent="true"
android:orientation="horizontal" >

<ProgressBar
android:id="@+id/probar"
style="?android:attr/progressBarStyleLarge"
android:layout_width="wrap_content"
android:layout_height="wrap_content" />

<TextView
android:id="@+id/download_rate"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:text="" />

<TextView
android:id="@+id/load_rate"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:text="" />
</LinearLayout>

</RelativeLayout>
8 changes: 8 additions & 0 deletions vitamio-sample/res/values/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -6,4 +6,12 @@
<string name="stream_video">Play Streaming Video</string>
<string name="local_audio">Play Audio from Local File</string>
<string name="res_audio">Play Audio from Resources</string>
<string name="title_activity_video_subtitle_demo">VideoSubtitleDemo</string>
<string name="action_settings">Settings</string>
<string name="subtitle1">MediaPlayer Subtitles</string>
<string name="subtitle12">VideoView Subtitles</string>
<string name="title_activity_media_player_subtitle">MediaPlayerSubtitle</string>
<string name="title_activity_video_view_subtitle">VideoViewSubtitle</string>
<string name="title_activity_video_subtitle_list">VideoSubtitleList</string>
<string name="title_activity_video_buffer">VideoBuffer</string>
</resources>
Original file line number Diff line number Diff line change
@@ -1,3 +1,18 @@
/*
* Copyright (C) 2013 yixia.com
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package io.vov.vitamio.demo;

import android.app.Activity;
Expand Down
156 changes: 156 additions & 0 deletions vitamio-sample/src/io/vov/vitamio/demo/MediaPlayerSubtitle.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,156 @@
/*
* Copyright (C) 2013 yixia.com
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

package io.vov.vitamio.demo;

import java.io.IOException;

import io.vov.vitamio.LibsChecker;
import io.vov.vitamio.MediaPlayer;
import io.vov.vitamio.MediaPlayer.OnPreparedListener;
import io.vov.vitamio.MediaPlayer.OnTimedTextListener;

import android.os.Bundle;
import android.os.Environment;
import android.app.Activity;
import android.graphics.PixelFormat;
import android.view.SurfaceHolder;
import android.view.SurfaceHolder.Callback;
import android.view.SurfaceView;
import android.widget.TextView;
import android.widget.Toast;

public class MediaPlayerSubtitle extends Activity implements Callback, OnPreparedListener, OnTimedTextListener {

SurfaceView splayer;
SurfaceHolder sholder;
TextView tv;
private MediaPlayer mediaPlayer;
private String path = "";

@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
if (!LibsChecker.checkVitamioLibs(this))
return;
setContentView(R.layout.subtitle1);
tv = (TextView) findViewById(R.id.sub1);
splayer = (SurfaceView) findViewById(R.id.surface);
sholder = splayer.getHolder();
sholder.setFormat(PixelFormat.RGBA_8888);
sholder.addCallback(this);
}

private void playVideo() {
try {
if (path == "") {
// Tell the user to provide an audio file URL.
Toast.makeText(MediaPlayerSubtitle.this, "Please edit MediaPlayer Activity, " + "and set the path variable to your media file path." + " Your media file must be stored on sdcard.", Toast.LENGTH_LONG).show();
return;
}
mediaPlayer = new MediaPlayer(this);
mediaPlayer.setDataSource(path);
mediaPlayer.setDisplay(sholder);
mediaPlayer.prepareAsync();
mediaPlayer.setOnPreparedListener(this);

mediaPlayer.setOnTimedTextListener(this);

// TODO Auto-generated catch block
} catch (IllegalArgumentException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (IllegalStateException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (SecurityException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}

@Override
public void surfaceChanged(SurfaceHolder holder, int format, int width, int height) {
// TODO Auto-generated method stub

}

@Override
public void surfaceCreated(SurfaceHolder holder) {
// TODO Auto-generated method stub
playVideo();
}

@Override
public void surfaceDestroyed(SurfaceHolder holder) {
// TODO Auto-generated method stub

}

private void startVPback() {

mediaPlayer.start();
}

@Override
public void onPrepared(MediaPlayer arg0) {

// TODO Auto-generated method stub
startVPback();
mediaPlayer.addTimedTextSource(Environment.getExternalStorageDirectory() + "/12.srt");
mediaPlayer.setTimedTextShown(true);
}

@Override
protected void onPause() {
// TODO Auto-generated method stub
super.onPause();
relaMediaPlay();
}

private void relaMediaPlay() {
// TODO Auto-generated method stub
if (mediaPlayer != null) {
mediaPlayer.release();
mediaPlayer = null;
}

}

@Override
protected void onDestroy() {
// TODO Auto-generated method stub
super.onDestroy();
relaMediaPlay();

}

@Override
public void onTimedText(String text) {
// TODO Auto-generated method stub
tv.setText(text);
}

@Override
public void onTimedTextUpdate(byte[] pixels, int width, int height) {
// TODO Auto-generated method stub

}

}
Loading

0 comments on commit 7920cb2

Please sign in to comment.