Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

adding duration to Media table and model

  • Loading branch information...
commit 73b1507a5564c3af891b287f6cb1006eedf14a70 1 parent 612839e
vitriolix vitriolix authored
9 app/src/info/guardianproject/mrapp/db/StoryMakerDB.java
View
@@ -30,6 +30,7 @@ public void onUpgrade(SQLiteDatabase db, int oldVersion, int newVersion) {
if ((oldVersion < 3) && (newVersion == 3)) {
db.execSQL(StoryMakerDB.Schema.Media.UPDATE_TABLE_MEDIA_ADD_TRIM_START);
db.execSQL(StoryMakerDB.Schema.Media.UPDATE_TABLE_MEDIA_ADD_TRIM_END);
+ db.execSQL(StoryMakerDB.Schema.Media.UPDATE_TABLE_MEDIA_ADD_DURATION);
}
}
@@ -106,6 +107,7 @@ public void onUpgrade(SQLiteDatabase db, int oldVersion, int newVersion) {
public static final String COL_CLIP_INDEX = "clip_index";
public static final String COL_TRIM_START = "trim_start";
public static final String COL_TRIM_END = "trim_end";
+ public static final String COL_DURATION = "duration";
private static final String CREATE_TABLE_MEDIA = "create table " + NAME + " ("
+ ID + " integer primary key autoincrement, "
@@ -115,7 +117,8 @@ public void onUpgrade(SQLiteDatabase db, int oldVersion, int newVersion) {
+ COL_CLIP_TYPE + " text not null, "
+ COL_CLIP_INDEX + " integer not null,"
+ COL_TRIM_START + " integer,"
- + COL_TRIM_END + " integer"
+ + COL_TRIM_END + " integer,"
+ + COL_DURATION + " integer"
+ "); ";
private static final String UPDATE_TABLE_MEDIA_ADD_TRIM_START = "alter table " + NAME + " "
@@ -125,6 +128,10 @@ public void onUpgrade(SQLiteDatabase db, int oldVersion, int newVersion) {
private static final String UPDATE_TABLE_MEDIA_ADD_TRIM_END = "alter table " + NAME + " "
+ "ADD COLUMN "
+ COL_TRIM_END + " integer;";
+
+ private static final String UPDATE_TABLE_MEDIA_ADD_DURATION = "alter table " + NAME + " "
+ + "ADD COLUMN "
+ + COL_DURATION + " integer;";
}
// public static final String DB_SCHEMA = Lessons.CREATE_TABLE_LESSONS
63 app/src/info/guardianproject/mrapp/model/Media.java
View
@@ -22,13 +22,14 @@
protected int sceneId; // foreign key to the Scene which holds this media
protected int trimStart;
protected int trimEnd;
+ protected int duration;
public Media(Context context) {
this.context = context;
}
public Media(Context context, int id, String path, String mimeType, String clipType, int clipIndex,
- int sceneId, int trimStart, int trimEnd) {
+ int sceneId, int trimStart, int trimEnd, int duration) {
super();
this.context = context;
this.id = id;
@@ -39,6 +40,7 @@ public Media(Context context, int id, String path, String mimeType, String clipT
this.sceneId = sceneId;
this.trimStart = trimStart;
this.trimEnd = trimEnd;
+ this.duration = duration;
}
public Media(Context context, Cursor cursor) {
@@ -60,7 +62,9 @@ public Media(Context context, Cursor cursor) {
cursor.getInt(cursor
.getColumnIndex(StoryMakerDB.Schema.Media.COL_TRIM_START)),
cursor.getInt(cursor
- .getColumnIndex(StoryMakerDB.Schema.Media.COL_TRIM_END)));
+ .getColumnIndex(StoryMakerDB.Schema.Media.COL_TRIM_END)),
+ cursor.getInt(cursor
+ .getColumnIndex(StoryMakerDB.Schema.Media.COL_DURATION)));
}
/***** Table level static methods *****/
@@ -81,6 +85,45 @@ public static Media get(Context context, int id) {
return null;
}
}
+
+ /***** Calculated object level methods *****/
+
+ /**
+ * @return 0.0-1.0 percent into the clip to start play
+ */
+ public float getTrimmedStartPercent() {
+ return (trimStart + 1) / 100F;
+ }
+
+ /**
+ * @return 0.0-1.0 percent into the clip to end play
+ */
+ public float getTrimmedEndPercent() {
+ return (trimEnd + 1) / 100F;
+ }
+
+ /**
+ * @return milliseconds into clip trimmed clip to start playback
+ */
+ public int getTrimmedStartTime() {
+ return Math.round(getTrimmedStartPercent() * duration);
+ }
+
+ /**
+ * @return milliseconds to end of trimmed clip
+ */
+ public int getTrimmedEndTime() {
+ return Math.round(getTrimmedEndPercent() * duration);
+ }
+
+ /**
+ * @return milliseconds trimmed clip will last
+ */
+ public int getTrimmedDuration() {
+ return getTrimmedEndTime() - getTrimmedStartTime();
+ }
+
+ /***** Object level methods *****/
/*
@@ -147,6 +190,7 @@ private ContentValues getValues() {
values.put(StoryMakerDB.Schema.Media.COL_SCENE_ID, sceneId);
values.put(StoryMakerDB.Schema.Media.COL_TRIM_START, trimStart);
values.put(StoryMakerDB.Schema.Media.COL_TRIM_END, trimEnd);
+ values.put(StoryMakerDB.Schema.Media.COL_DURATION, duration);
return values;
}
@@ -308,4 +352,19 @@ public int getTrimEnd() {
public void setTrimEnd(int trimEnd) {
this.trimEnd = trimEnd;
}
+
+
+ /**
+ * @return the duration
+ */
+ public int getDuration() {
+ return duration;
+ }
+
+ /**
+ * @param duration the duration to set
+ */
+ public void setDuration(int duration) {
+ this.duration = duration;
+ }
}
Please sign in to comment.
Something went wrong with that request. Please try again.