Video List [sample]

117 views
Skip to first unread message

nikhil baby

unread,
Apr 29, 2017, 12:44:01 AM4/29/17
to DroidScript
I have made a video list for showing video list like in the videos viewer app.

This sample can produce:-

list videos and show them in a list with file suze , duration, and thumbnail.

I think this will sample will help someine.

Download the SPK from down link:-

https://www.dropbox.com/s/96vmuwrju0t2o05/video%20list.spk?dl=0

YOU CAN CHANGE THIS DOWN VAR TO true TO HAVE A ANIMATED LIST

var Animation = false;
change to ↓
var Animation = true;


:)

Steve Garman

unread,
Apr 29, 2017, 1:59:49 AM4/29/17
to DroidScript
Thanks for that Nikhil.

Unbelievably, I only have one MP4 file on my phone so I can't give it an exhaustive test but I am sure lots of people will find it a good example of one way to design this sort of list.

ridwan martono

unread,
Apr 29, 2017, 2:58:37 AM4/29/17
to DroidScript
Thank you for the example :)

ridwan martono

unread,
Apr 29, 2017, 11:17:39 AM4/29/17
to DroidScript
I have 3gp and mp4 videos, I have tested your SPK but only shows app progress no videos Ares shown

Steve Garman

unread,
Apr 29, 2017, 11:50:46 AM4/29/17
to DroidScript
Ridwan,

Have you looked at the code?

You asked for a ListFolder, so Nikhil sensibly assumed you wanted to list the mp4s in a folder.

The variable fld at the top of the code contains the folder that houses the videos. You will probably need to change the file path to suit yourself.

He has also assumed MP4 files and used that in the filter when he uses
app.ListFolder( fld, ".mp4" )
You can take the filter out if you want to select all files from the folder.

nikhil baby

unread,
Apr 29, 2017, 12:30:53 PM4/29/17
to DroidScript
Steve is rigth Ridwan!!!!

Chris

unread,
Apr 29, 2017, 5:55:01 PM4/29/17
to DroidScript
It hangs on my phone too. The progress spinner just stays, nothing else happens. Had to exit the app.

nikhil baby

unread,
Apr 29, 2017, 10:19:25 PM4/29/17
to DroidScript
i think you phone has a bad video file.
I my sample it uses videoview.SetOnReady() method to create the list.
So if you have any bad video file. the sample will staying in loading screen.
Do you know how to fix this!!!!

Netpower8

unread,
Apr 29, 2017, 11:53:34 PM4/29/17
to DroidScript
this one is not working on my device also. which is on kitkat os.

Netpower8

unread,
Apr 29, 2017, 11:55:18 PM4/29/17
to DroidScript
trying to debug it

Netpower8

unread,
Apr 30, 2017, 12:36:23 AM4/30/17
to DroidScript
found the error. this line

      player.SetFile(fld + videos[i]);

should be this line... the path string was not passed correctly
  
      player.SetFile(fld + '/' + videos[i]);

missing a " / " on the path.

Netpower8

unread,
Apr 30, 2017, 12:49:22 AM4/30/17
to DroidScript
or change this line

fld =  "/sdcard/DCIM/Camera";

to this

fld =  "/sdcard/DCIM/Camera/";

Brad Yoch

unread,
Feb 8, 2018, 2:59:14 AM2/8/18
to DroidScript
Works then blanks out
I am unable to post the spk


//FOLDER TO SCAN VIDEOS
ext = app.GetExternalFolder();
//fld = ext
//"/sdcard/Temp";

//ENABLE OR DISABLE VIDEO LIST ANIMATION
Animation = false;

app.SetDebugEnabled( false );
//Called when application is started.
function OnStart()
{
//app.ShowProgress( );

//Create a layout with objects vertically centered.
layMain = app.CreateLayout( "linear", "FillXY" );
layMain.SetBackColor( "#ffffff" );

//Create a full screen scroller
scroll = app.CreateScroller( 1.0, 1.0 );
layMain.AddChild( scroll );

//Create a layout inside scroller.
lay = app.CreateLayout( "Linear", "Left" );
scroll.AddChild( lay );


videos = app.ListFolder( ext, ".mp4" );
i = -1;

//Add layout to app.
app.AddLayout( layMain );

addVideoIcon();

}

function addVideoIcon()
{
if( i<videos.length-1 ){
i++

//Create horizontal sub-layout for buttons.
layCon = app.CreateLayout( "Absolute", "" );
layCon.SetBackColor( "#ffffff" );
lay.AddChild( layCon );

//Create horizontal sub-layout for buttons.
layHoriz = app.CreateLayout( "linear", "Horizontal" );
layCon.AddChild( layHoriz );

//Create video view.
player = app.CreateVideoView( 0.2, 1 );
layHoriz.AddChild( player );
player.SetOnReady( player_OnReady );
player.SetFile( ext+"/" + videos[i] );

//Create a layout with objects vertically centered.
layV = app.CreateLayout( "linear", "Left" );
layHoriz.AddChild( layV );

}
else app.HideProgress();
}


//Called when file is ready to play.
function player_OnReady()
{

//Create some text.
txt = app.CreateText( " " + videos[i], 0.8, null, "Left" );
txt.SetEllipsize( "middle" );
txt.SetTextSize( 16 );
txt.SetTextColor( "#363636" );
layV.AddChild( txt );

//Create horizontal sub-layout for buttons.
layHoriz2 = app.CreateLayout( "linear", "Horizontal" );
layV.AddChild( layHoriz2 );

//Create some text.
txt = app.CreateText( " " + bytesToSize( app.GetFileSize( ext+"/"+ + videos[i] ) ), 0.4, null, "Left" );
txt.SetTextSize( 13 );
txt.SetTextColor( "#999999" );
layHoriz2.AddChild( txt );

//Create some text.
txt = app.CreateText( millisToMinutesAndSeconds( player.GetDuration() ), 0.4, null, "Right" );
txt.SetTextSize( 13 );
txt.SetTextColor( "#999999" );
layHoriz2.AddChild( txt );

//Add seperator to menu layout.
var sep = app.CreateImage( null, 1,0.001,"fix", 2,2 );
sep.SetSize( -1, 1, "px" );
sep.SetColor( "#cccccc" );
lay.AddChild( sep );

//Create a button 1/3 of screen width and 1/10 screen height.
btn = app.CreateButton( "Press Me", 0.3, 0.1 );
btn.SetSize( layCon.GetWidth( ), layCon.GetHeight( ) );
btn.SetBackColor( "#00cc22cc" );
btn.VideoUrl = ext +"/"+ videos[i];
btn.SetOnTouch( Videolist );
layCon.AddChild( btn );

player.Play();
app.SetVolume( 0, 0 );
player.SeekTo( 1 );
if( Animation==false ) player.Pause();
addVideoIcon();
}


function bytesToSize(bytes) {
var sizes = [ 'Bytes', 'KB' , 'MB' , 'GB' , 'TB' ];
if (bytes == 0) return '0 Byte' ;
var i = parseInt( Math .floor( Math .log(bytes) /
Math .log( 1024 )));
return Math .round(bytes / Math .pow( 1024 , i), 2) + ' ' + sizes[i];
}

function millisToMinutesAndSeconds(d) {
d = Number (d);
var h = Math .floor(d / 3600 );
var m = Math .floor(d % 3600 / 60 );
var s = Math .floor(d % 3600 % 60 );
var hDisplay = h > 0 ? h + (h == 1 ? ":" : ":" ) : "" ;
var mDisplay = m > 0 ? m + (m == 1 ?
":" : ":" ) : "" ;
var sDisplay = s > 0 ? s + (s == 1 ? " " : " " ) : "" ;
return hDisplay + mDisplay + sDisplay;
}
function Videolist(){this.SetBackColor( "#50999999" ); VideoList_OnTouch( this.VideoUrl );this.SetBackColor( "#00999999" );}


//THIS FUNCTION CALLS WHEN USER
//TOUCH A LIST
//video argument contains video url
function VideoList_OnTouch( video)
{
app.ShowPopup( video );
}

Reply all
Reply to author
Forward
0 new messages