
Recherche avancée
Médias (29)
-
#7 Ambience
16 octobre 2011, par
Mis à jour : Juin 2015
Langue : English
Type : Audio
-
#6 Teaser Music
16 octobre 2011, par
Mis à jour : Février 2013
Langue : English
Type : Audio
-
#5 End Title
16 octobre 2011, par
Mis à jour : Février 2013
Langue : English
Type : Audio
-
#3 The Safest Place
16 octobre 2011, par
Mis à jour : Février 2013
Langue : English
Type : Audio
-
#4 Emo Creates
15 octobre 2011, par
Mis à jour : Février 2013
Langue : English
Type : Audio
-
#2 Typewriter Dance
15 octobre 2011, par
Mis à jour : Février 2013
Langue : English
Type : Audio
Autres articles (105)
-
MediaSPIP version 0.1 Beta
16 avril 2011, parMediaSPIP 0.1 beta est la première version de MediaSPIP décrétée comme "utilisable".
Le fichier zip ici présent contient uniquement les sources de MediaSPIP en version standalone.
Pour avoir une installation fonctionnelle, il est nécessaire d’installer manuellement l’ensemble des dépendances logicielles sur le serveur.
Si vous souhaitez utiliser cette archive pour une installation en mode ferme, il vous faudra également procéder à d’autres modifications (...) -
MediaSPIP 0.1 Beta version
25 avril 2011, parMediaSPIP 0.1 beta is the first version of MediaSPIP proclaimed as "usable".
The zip file provided here only contains the sources of MediaSPIP in its standalone version.
To get a working installation, you must manually install all-software dependencies on the server.
If you want to use this archive for an installation in "farm mode", you will also need to proceed to other manual (...) -
Amélioration de la version de base
13 septembre 2013Jolie sélection multiple
Le plugin Chosen permet d’améliorer l’ergonomie des champs de sélection multiple. Voir les deux images suivantes pour comparer.
Il suffit pour cela d’activer le plugin Chosen (Configuration générale du site > Gestion des plugins), puis de configurer le plugin (Les squelettes > Chosen) en activant l’utilisation de Chosen dans le site public et en spécifiant les éléments de formulaires à améliorer, par exemple select[multiple] pour les listes à sélection multiple (...)
Sur d’autres sites (10170)
-
Video created using H263 codec and ffmpeg does not play on android device [closed]
21 mars 2013, par susheel tickooI have created a video using FFmpeg and H263 codec. But when I play the video on an Android device the player is unable to play it. I have used both the extensions .mp4 and .3gp.
void generate(JNIEnv *pEnv, jobject pObj,jobjectArray stringArray,int famerate,int width,int height,jstring videoFilename)
{
AVCodec *codec;
AVCodecContext *c= NULL;
//int framesnum=5;
int i,looper, out_size, size, x, y,encodecbuffsize,j;
__android_log_write(ANDROID_LOG_INFO, "record","************into generate************");
int imagecount= (*pEnv)->GetArrayLength(pEnv, stringArray);
__android_log_write(ANDROID_LOG_INFO, "record","************got magecount************");
int retval=-10;
FILE *f;
AVFrame *picture,*encoded_avframe;
uint8_t *encodedbuffer;
jbyte *raw_record;
char logdatadata[100];
int returnvalue = -1,numBytes =-1;
const char *gVideoFileName = (char *)(*pEnv)->GetStringUTFChars(pEnv, videoFilename, NULL);
__android_log_write(ANDROID_LOG_INFO, "record","************got video file name************");
/* find the mpeg1 video encoder */
codec = avcodec_find_encoder(CODEC_ID_H264);
if (!codec) {
__android_log_write(ANDROID_LOG_INFO, "record","codec not found");
exit(1);
}
c= avcodec_alloc_context();
/*c->bit_rate = 400000;
c->width = width;
c->height = height;
c->time_base= (AVRational){1,famerate};
c->gop_size = 12; // emit one intra frame every ten frames
c->max_b_frames=0;
c->pix_fmt = PIX_FMT_YUV420P;
c->codec_type = AVMEDIA_TYPE_VIDEO;
c->codec_id = CODEC_ID_H263;*/
c->bit_rate = 400000;
// resolution must be a multiple of two
c->width = 176;
c->height = 144;
c->pix_fmt = PIX_FMT_YUV420P;
c->qcompress = 0.0;
c->qblur = 0.0;
c->gop_size = 20; //or 1
c->sub_id = 1;
c->workaround_bugs = FF_BUG_AUTODETECT;
//pFFmpeg->c->time_base = (AVRational){1,25};
c->time_base.num = 1;
c->time_base.den = famerate;
c->max_b_frames = 0; //pas de B frame en H263
// c->opaque = opaque;
c->dct_algo = FF_DCT_AUTO;
c->idct_algo = FF_IDCT_AUTO;
//lc->rtp_mode = 0;
c->rtp_payload_size = 1000;
c->rtp_callback = 0; // ffmpeg_rtp_callback;
c->flags |= CODEC_FLAG_QSCALE;
c->mb_decision = FF_MB_DECISION_RD;
c->thread_count = 1;
#define DEFAULT_RATE (16 * 8 * 1024)
c->rc_min_rate = DEFAULT_RATE;
c->rc_max_rate = DEFAULT_RATE;
c->rc_buffer_size = DEFAULT_RATE * 64;
c->bit_rate = DEFAULT_RATE;
sprintf(logdatadata, "------width from c ---- = %d",width);
__android_log_write(ANDROID_LOG_INFO, "record",logdatadata);
sprintf(logdatadata, "------height from c ---- = %d",height);
__android_log_write(ANDROID_LOG_INFO, "record",logdatadata);
__android_log_write(ANDROID_LOG_INFO, "record","************Found codec and now opening it************");
/* open it */
retval = avcodec_open(c, codec);
if ( retval < 0)
{
sprintf(logdatadata, "------avcodec_open ---- retval = %d",retval);
__android_log_write(ANDROID_LOG_INFO, "record",logdatadata);
__android_log_write(ANDROID_LOG_INFO, "record","could not open codec");
exit(1);
}
__android_log_write(ANDROID_LOG_INFO, "record","statement 5");
f = fopen(gVideoFileName, "ab");
if (!f) {
__android_log_write(ANDROID_LOG_INFO, "record","could not open video file");
exit(1);
}
__android_log_write(ANDROID_LOG_INFO, "record", "***************Allocating encodedbuffer*********\n");
encodecbuffsize = avpicture_get_size(PIX_FMT_RGB24, c->width, c->height);
sprintf(logdatadata, "encodecbuffsize = %d",encodecbuffsize);
__android_log_write(ANDROID_LOG_INFO, "record",logdatadata);
encodedbuffer = malloc(encodecbuffsize);
jclass cls = (*pEnv)->FindClass(pEnv, "com/canvasm/mediclinic/VideoGenerator");
jmethodID mid = (*pEnv)->GetMethodID(pEnv, cls, "videoProgress", "(Ljava/lang/String;)Ljava/lang/String;");
jmethodID mid_delete = (*pEnv)->GetMethodID(pEnv, cls, "deleteTempFile", "(Ljava/lang/String;)Ljava/lang/String;");
if (mid == 0)
return;
__android_log_write(ANDROID_LOG_INFO, "native","got method id");
for(i=0;i<=imagecount;i++) {
jboolean isCp;
int progress = 0;
float temp;
jstring string;
if(i==imagecount)
string = (jstring) (*pEnv)->GetObjectArrayElement(pEnv, stringArray, imagecount-1);
else
string = (jstring) (*pEnv)->GetObjectArrayElement(pEnv, stringArray, i);
const char *rawString = (*pEnv)->GetStringUTFChars(pEnv, string, &isCp);
__android_log_write(ANDROID_LOG_INFO, "record",rawString);
picture = OpenImage(rawString,width,height);
//WriteJPEG(c,picture,i);
// encode video
memset(encodedbuffer,0,encodecbuffsize);
//do{
for(looper=0;looper<5;looper++)
{
memset(encodedbuffer,0,encodecbuffsize);
out_size = avcodec_encode_video(c, encodedbuffer, encodecbuffsize, picture);
sprintf(logdatadata, "avcodec_encode_video ----- out_size = %d \n",out_size );
__android_log_write(ANDROID_LOG_INFO, "record",logdatadata);
if(out_size>0)
break;
}
__android_log_write(ANDROID_LOG_INFO, "record","*************Start looping for same image*******");
returnvalue = fwrite(encodedbuffer, 1, out_size, f);
sprintf(logdatadata, "fwrite ----- returnvalue = %d \n",returnvalue );
__android_log_write(ANDROID_LOG_INFO, "record",logdatadata);
__android_log_write(ANDROID_LOG_INFO, "record","*************End looping for same image*******");
// publishing progress
progress = ((i*100)/(imagecount+1))+15;//+1 is for last frame duplicated entry
if(progress<20 )
progress =20;
if(progress>=95 )
progress =95;
sprintf(logdatadata, "%d",progress );
jstring jstrBuf = (*pEnv)->NewStringUTF(pEnv, logdatadata);
(*pEnv)->CallObjectMethod(pEnv, pObj, mid,jstrBuf);
if(i>0)
(*pEnv)->CallObjectMethod(pEnv, pObj, mid_delete,string);
}
/* get the delayed frames */
for(; out_size; i++) {
fflush(stdout);
out_size = avcodec_encode_video(c, encodedbuffer, encodecbuffsize, NULL);
fwrite(encodedbuffer, 20, out_size, f);
}
/* add sequence end code to have a real mpeg file */
encodedbuffer[0] = 0x00;
encodedbuffer[1] = 0x00;
encodedbuffer[2] = 0x01;
encodedbuffer[3] = 0xb7;
fwrite(encodedbuffer, 1, 4, f);
fclose(f);
free(encodedbuffer);
avcodec_close(c);
av_free(c);
__android_log_write(ANDROID_LOG_INFO, "record","Video created ");
// last updation of 100%
sprintf(logdatadata, "%d",100 );
jstring jstrBuf = (*pEnv)->NewStringUTF(pEnv, logdatadata);
(*pEnv)->CallObjectMethod(pEnv, pObj, mid,jstrBuf);
}
AVFrame* OpenImage(const char* imageFileName,int w,int h)
{
AVFrame *pFrame;
AVCodec *pCodec ;
AVFormatContext *pFormatCtx;
AVCodecContext *pCodecCtx;
uint8_t *buffer;
int frameFinished,framesNumber = 0,retval = -1,numBytes=0;
AVPacket packet;
char logdatadata[100];
//__android_log_write(ANDROID_LOG_INFO, "OpenImage",imageFileName);
if(av_open_input_file(&pFormatCtx, imageFileName, NULL, 0, NULL)!=0)
//if(avformat_open_input(&pFormatCtx,imageFileName,NULL,NULL)!=0)
{
__android_log_write(ANDROID_LOG_INFO, "record",
"Can't open image file ");
return NULL;
}
pCodecCtx = pFormatCtx->streams[0]->codec;
pCodecCtx->width = w;
pCodecCtx->height = h;
pCodecCtx->pix_fmt = PIX_FMT_YUV420P;
// Find the decoder for the video stream
pCodec = avcodec_find_decoder(pCodecCtx->codec_id);
if (!pCodec)
{
__android_log_write(ANDROID_LOG_INFO, "record",
"Can't open image file ");
return NULL;
}
pFrame = avcodec_alloc_frame();
numBytes = avpicture_get_size(PIX_FMT_YUV420P, pCodecCtx->width, pCodecCtx->height);
buffer = (uint8_t *) av_malloc(numBytes * sizeof(uint8_t));
sprintf(logdatadata, "numBytes = %d",numBytes);
__android_log_write(ANDROID_LOG_INFO, "record",logdatadata);
retval = avpicture_fill((AVPicture *) pFrame, buffer, PIX_FMT_YUV420P, pCodecCtx->width, pCodecCtx->height);
// Open codec
if(avcodec_open(pCodecCtx, pCodec)<0)
{
__android_log_write(ANDROID_LOG_INFO, "record","Could not open codec");
return NULL;
}
if (!pFrame)
{
__android_log_write(ANDROID_LOG_INFO, "record","Can't allocate memory for AVFrame\n");
return NULL;
}
int readval = -5;
while (readval = av_read_frame(pFormatCtx, &packet) >= 0)
{
if(packet.stream_index != 0)
continue;
int ret = avcodec_decode_video2(pCodecCtx, pFrame, &frameFinished, &packet);
sprintf(logdatadata, "avcodec_decode_video2 ret = %d",ret);
__android_log_write(ANDROID_LOG_INFO, "record",logdatadata);
if (ret > 0)
{
__android_log_write(ANDROID_LOG_INFO, "record","Frame is decoded\n");
pFrame->quality = 4;
av_free_packet(&packet);
av_close_input_file(pFormatCtx);
return pFrame;
}
else
{
__android_log_write(ANDROID_LOG_INFO, "record","error while decoding frame \n");
}
}
sprintf(logdatadata, "readval = %d",readval);
__android_log_write(ANDROID_LOG_INFO, "record",logdatadata);
}The
generate
method takes a list of strings (path to images) and converts them to video and theOpenImage
method is responsible for convertign a single image toAVFrame
. -
FFmpeg : calculate time to convert images and .mp3 to a video
6 avril 2013, par DomenKIs there any formula that I can use to calculate the time that FFmpeg uses to convert a single .jpg image and .mp3 song to a video ?
I am using the following code :
ffmpeg -loop 1 -r ntsc -i image.jpg -i song.mp3 -c:a copy -c:v libx264 \ -preset fast -threads 0 -shortest
Lets say we have an image with X resolution and .mp3 length of L. Would the formula be :
time = X * L(in seconds) ?
Thanks for any tips.
-
Getting Error during executin native android code
3 avril 2013, par dilipkaklotarError on my console
bash : cannot set terminal process group (-1) : Inappropriate ioctl for device
bash : no job control in this shell
Your group is currently "mkpasswd". This indicates that your
gid is not in /etc/group and your uid is not in /etc/passwd.The /etc/passwd (and possibly /etc/group) files should be rebuilt.
See the man pages for mkpasswd and mkgroup then, for example, runmkpasswd -l [-d] > /etc/passwd
mkgroup -l [-d] > /etc/groupNote that the -d switch is necessary for domain users.
]0 ; -
[32mDILIP@DILIP-PC -[33m -[0m
$public class VideoBrowser extends ListActivity implements ListView.OnScrollListener {
/*this part communicates with native code through jni (java native interface)*/
//load the native library
static {
System.loadLibrary("ffmpeg");
System.loadLibrary("ffmpeg-test-jni");
}
//declare the jni functions
private static native void naInit(String _videoFileName);
private static native int[] naGetVideoResolution();
private static native String naGetVideoCodecName();
private static native String naGetVideoFormatName();
private static native void naClose();
private void showVideoInfo(final File _file) {
String videoFilename = _file.getAbsolutePath();
naInit(videoFilename);
int[] prVideoRes = naGetVideoResolution();
String prVideoCodecName = naGetVideoCodecName();
String prVideoFormatName = naGetVideoFormatName();
naClose();
String displayText = "Video: " + videoFilename + "\n";
displayText += "Video Resolution: " + prVideoRes[0] + "x" + prVideoRes[1] + "\n";
displayText += "Video Codec: " + prVideoCodecName + "\n";
displayText += "Video Format: " + prVideoFormatName + "\n";
text_titlebar_text.setText(displayText);
}
/*the rest of the file deals with UI and other stuff*/
private Context mContext;
public static VideoBrowser self;
/**
* activity life cycle: this part of the source code deals with activity life cycle
*/
@Override
public void onCreate(Bundle icicle) {
super.onCreate(icicle);
mContext = this.getApplicationContext();
self = this;
initUI();
}
@Override
protected void onDestroy() {
super.onDestroy();
unbindDisplayEntries();
}
public void unbindDisplayEntries() {
if (displayEntries!=null) {
int l_count = displayEntries.size();
for (int i = 0; i < l_count; ++i) {
IconifiedTextSelected l_its = displayEntries.get(i);
if (l_its != null) {
Drawable l_dr = l_its.getIcon();
if (l_dr != null) {
l_dr.setCallback(null);
l_dr = null;
}
}
}
}
if (l_displayEntries!=null) {
int l_count = l_displayEntries.size();
for (int i = 0; i < l_count; ++i) {
IconifiedTextSelected l_its = l_displayEntries.get(i);
if (l_its != null) {
Drawable l_dr = l_its.getIcon();
if (l_dr != null) {
l_dr.setCallback(null);
l_dr = null;
}
}
}
}
}
/**
* Data: this part of the code deals with data processing
*/
public List<iconifiedtextselected> displayEntries = new ArrayList<iconifiedtextselected>();
public static List<iconifiedtextselected> l_displayEntries = new ArrayList<iconifiedtextselected>();;
/**load images
* this part of code deals with loading of images
*/
private File currentDirectory;
public int media_browser_load_option = 2;
private static int last_media_browser_load_option = 2;
private static int number_of_icons = 0;
private static final String upOneLevel = "..";
LoadVideoTask loadTask;
private void loadVideosFromDirectory(String _dir) {
try {
loadTask = new LoadVideoTask();
loadTask.execute(_dir);
} catch (Exception e) {
Toast.makeText(this, "Load media fail!", Toast.LENGTH_SHORT).show();
}
}
private void getVideosFromDirectoryNonRecurAddParent(File _dir) {
//add the upper one level data
if (_dir.getParent()!=null) {
this.displayEntries.add(new IconifiedTextSelected(
upOneLevel,
getResources().getDrawable(R.drawable.folderback),
false, false, 0));
}
}
private void getVideosFromDirectoryNonRecur(File _dir) {
Drawable folderIcon = this.getResources().getDrawable(R.drawable.normalfolder);
//add the
if (!_dir.isDirectory()) {
return;
}
File[] files = _dir.listFiles();
if (files == null) {
return;
}
Drawable videoIcon = null;
int l_iconType = 0;
for (File currentFile : files) {
if (currentFile.isDirectory()) {
//if it's a directory
this.displayEntries.add(new IconifiedTextSelected(
currentFile.getPath(),
folderIcon, false, false, 0));
} else {
String l_filename = currentFile.getName();
if (checkEndsWithInStringArray(l_filename,
getResources().getStringArray(R.array.fileEndingVideo))) {
if (number_of_icons < 10) {
videoIcon = null;
++number_of_icons;
l_iconType = 22;
} else {
videoIcon = null;
l_iconType = 2;
}
this.displayEntries.add(new IconifiedTextSelected(
currentFile.getPath(),
videoIcon, false, false, l_iconType));
}
}
}
}
private void getVideosFromDirectoryRecur(File _dir) {
Drawable videoIcon = null;
File[] files = _dir.listFiles();
int l_iconType = 2;
if (files == null) {
return;
}
for (File currentFile : files) {
if (currentFile.isDirectory()) {
getVideosFromDirectoryRecur(currentFile);
continue;
} else {
String l_filename = currentFile.getName();
//if it's an image file
if (checkEndsWithInStringArray(l_filename,
getResources().getStringArray(R.array.fileEndingVideo))) {
if (number_of_icons < 10) {
videoIcon = null;
++number_of_icons;
l_iconType = 22;
} else {
videoIcon = null;
l_iconType = 2;
}
this.displayEntries.add(new IconifiedTextSelected(
currentFile.getPath(),
videoIcon, false, false, l_iconType));
}
}
}
}
private void getVideosFromGallery() {
Drawable videoIcon = null;
Uri uri = MediaStore.Video.Media.EXTERNAL_CONTENT_URI;
String[] projection = {MediaStore.Video.Media.DATA};
Cursor l_cursor = this.managedQuery(uri, projection, null, null, null);
int videoNameColumnIndex;
String videoFilename;
File videoFile;
int l_iconType = 2;
if (l_cursor!=null) {
if (l_cursor.moveToFirst()) {
do {
videoNameColumnIndex = l_cursor.getColumnIndexOrThrow(
MediaStore.Images.Media.DATA);
videoFilename = l_cursor.getString(videoNameColumnIndex);
videoFile = new File(videoFilename);
if (!videoFile.exists()) {
continue;
}
if (number_of_icons <= 10) {
videoIcon = null;
++number_of_icons;
l_iconType = 22;
} else {
videoIcon = null;
l_iconType = 2;
}
this.displayEntries.add(new IconifiedTextSelected(
videoFile.getAbsolutePath(),
videoIcon, false, false, l_iconType));
} while (l_cursor.moveToNext());
}
}
if (l_cursor!=null) {
l_cursor.close();
}
}
private boolean checkEndsWithInStringArray(String checkItsEnd,
String[] fileEndings){
for(String aEnd : fileEndings){
if(checkItsEnd.endsWith(aEnd))
return true;
}
return false;
}
private class LoadVideoTask extends AsyncTask {
@Override
protected void onPreExecute() {
System.gc();
displayEntries.clear();
showDialog(DIALOG_LOAD_MEDIA);
}
@Override
protected Void doInBackground(String... params) {
File l_root = new File(params[0]);
if (l_root.isDirectory()) {
number_of_icons = 0;
currentDirectory = l_root;
if (media_browser_load_option == 0) {
//list all videos in the root directory without going into sub folder
getVideosFromDirectoryNonRecurAddParent(l_root);
getVideosFromDirectoryNonRecur(l_root);
} else if (media_browser_load_option == 1) {
//list all videos in the root folder recursively
getVideosFromDirectoryRecur(l_root);
} else if (media_browser_load_option == 2) {
//list all videos in the gallery
getVideosFromGallery();
}
}
return null;
}
@Override
protected void onPostExecute(Void n) {
refreshUI();
dismissDialog(DIALOG_LOAD_MEDIA);
}
}
/**
* UI: this part of the source code deals with UI
*/
//bottom menu
private int currentFocusedBtn = 1;
private Button btn_bottommenu1;
private Button btn_bottommenu2;
private Button btn_bottommenu3;
//private Button btn_bottommenu4;
//title bar
private TextView text_titlebar_text;
private void initUI() {
this.requestWindowFeature(Window.FEATURE_NO_TITLE);
this.setContentView(R.layout.video_browser);
//title bar
text_titlebar_text = (TextView) findViewById(R.id.titlebar_text);
text_titlebar_text.setText("Click a video to display info");
//bottom menu
int l_btnWidth = this.getWindowManager().getDefaultDisplay().getWidth()/4;
btn_bottommenu1 = (Button) findViewById(R.id.video_browser_btn1);
//btn_bottommenu1 = (ActionMenuButton) findViewById(R.id.main_topsecretimport_btn1);
btn_bottommenu1.setWidth(l_btnWidth);
btn_bottommenu1.setOnClickListener(new View.OnClickListener() {
public void onClick(View v) {
btn_bottommenu1.setEnabled(false);
btn_bottommenu2.setEnabled(true);
btn_bottommenu3.setEnabled(true);
currentFocusedBtn = 1;
last_list_view_pos = 0;
media_browser_load_option = 2;
last_media_browser_load_option = media_browser_load_option;
loadVideosFromDirectory("/sdcard/");
}
});
btn_bottommenu2 = (Button) findViewById(R.id.video_browser_btn2);
btn_bottommenu2.setWidth(l_btnWidth);
btn_bottommenu2.setOnClickListener(new View.OnClickListener() {
public void onClick(View v) {
btn_bottommenu1.setEnabled(true);
btn_bottommenu2.setEnabled(false);
btn_bottommenu3.setEnabled(true);
currentFocusedBtn = 2;
last_list_view_pos = 0;
media_browser_load_option = 0;
last_media_browser_load_option = media_browser_load_option;
loadVideosFromDirectory("/sdcard/");
}
});
btn_bottommenu3 = (Button) findViewById(R.id.video_browser_btn3);
btn_bottommenu3.setWidth(l_btnWidth);
btn_bottommenu3.setOnClickListener(new View.OnClickListener() {
public void onClick(View v) {
btn_bottommenu1.setEnabled(true);
btn_bottommenu2.setEnabled(true);
btn_bottommenu3.setEnabled(false);
currentFocusedBtn = 3;
last_list_view_pos = 0;
media_browser_load_option = 1;
last_media_browser_load_option = media_browser_load_option;
loadVideosFromDirectory("/sdcard/");
}
});
media_browser_load_option = last_media_browser_load_option;
if (media_browser_load_option==2) {
btn_bottommenu1.setEnabled(false);
} else if (media_browser_load_option==0) {
btn_bottommenu2.setEnabled(false);
} else if (media_browser_load_option==1){
btn_bottommenu3.setEnabled(false);
}
loadVideosFromDirectory("/sdcard/");
}
//refresh the UI when the directoryEntries changes
private static int last_list_view_pos = 0;
public void refreshUI() {
int l_btnWidth = this.getWindowManager().getDefaultDisplay().getWidth()/4;
btn_bottommenu1.setWidth(l_btnWidth);
btn_bottommenu2.setWidth(l_btnWidth);
btn_bottommenu3.setWidth(l_btnWidth);
//btn_bottommenu4.setWidth(l_btnWidth);
SlowAdapter itla = new SlowAdapter(this);
itla.setListItems(this.displayEntries);
this.setListAdapter(itla);
getListView().setOnScrollListener(this);
int l_size = this.displayEntries.size();
if (l_size > 50) {
getListView().setFastScrollEnabled(true);
} else {
getListView().setFastScrollEnabled(false);
}
if (l_size > 0) {
if (last_list_view_pos < l_size) {
getListView().setSelection(last_list_view_pos);
} else {
getListView().setSelection(l_size-1);
}
}
registerForContextMenu(getListView());
}
@Override
public void onConfigurationChanged (Configuration newConfig) {
super.onConfigurationChanged(newConfig);
refreshUI();
}
static final int DIALOG_LOAD_MEDIA = 1;
static final int DIALOG_HELP = 2;
@Override
protected Dialog onCreateDialog(int id) {
switch(id) {
case DIALOG_LOAD_MEDIA:
ProgressDialog dialog = new ProgressDialog(this);
dialog.setTitle("Load Files");
dialog.setMessage("Please wait while loading...");
dialog.setIndeterminate(true);
dialog.setCancelable(true);
return dialog;
default:
return null;
}
}
/**
* scroll events methods: this part of the source code contain the control source code
* for handling scroll events
*/
private boolean mBusy = false;
private void disableButtons() {
btn_bottommenu1.setEnabled(false);
btn_bottommenu2.setEnabled(false);
btn_bottommenu3.setEnabled(false);
}
private void enableButtons() {
if (currentFocusedBtn!=1) {
btn_bottommenu1.setEnabled(true);
}
if (currentFocusedBtn!=2) {
btn_bottommenu2.setEnabled(true);
}
if (currentFocusedBtn!=3) {
btn_bottommenu3.setEnabled(true);
}
}
public void onScroll(AbsListView view, int firstVisibleItem,
int visibleItemCount, int totalItemCount) {
last_list_view_pos = view.getFirstVisiblePosition();
}
//private boolean mSaveMemory = false;
public void onScrollStateChanged(AbsListView view, int scrollState) {
switch (scrollState) {
case OnScrollListener.SCROLL_STATE_IDLE:
enableButtons();
mBusy = false;
int first = view.getFirstVisiblePosition();
int count = view.getChildCount();
int l_releaseTarget;
for (int i=0; i/if outofmemory, we try to clean up 10 view image resources,
//and try again
for (int j = 0; j < 10; ++j) {
l_releaseTarget = first - count - j;
if (l_releaseTarget > 0) {
IconifiedTextSelected l_its = displayEntries.get(l_releaseTarget);
IconifiedTextSelectedView l_itsv = (IconifiedTextSelectedView)
this.getListView().getChildAt(l_releaseTarget);
if (l_itsv!=null) {
l_itsv.setIcon(null);
}
if (l_its != null) {
Drawable l_dr = l_its.getIcon();
l_its.setIcon(null);
if (l_dr != null) {
l_dr.setCallback(null);
l_dr = null;
}
}
}
}
System.gc();
//after clean up, we try again
if (l_type == 1) {
l_icon = null;
} else if (l_type == 2) {
l_icon = null;
}
}
this.displayEntries.get(first+i).setIcon(l_icon);
if (l_icon != null) {
t.setIcon(l_icon);
t.setTag(null);
}
}
}
//System.gc();
break;
case OnScrollListener.SCROLL_STATE_TOUCH_SCROLL:
disableButtons();
mBusy = true;
break;
case OnScrollListener.SCROLL_STATE_FLING:
disableButtons();
mBusy = true;
break;
}
}
/**
* List item click action
*/
private File currentFile;
@Override
protected void onListItemClick(ListView l, View v, int position, long id) {
super.onListItemClick(l, v, position, id);
last_list_view_pos = position;
String selectedFileOrDirName = this.displayEntries.get((int)id).getText();
if (selectedFileOrDirName.equals(upOneLevel)) {
if (this.currentDirectory.getParent()!=null) {
last_list_view_pos = 0;
browseTo(this.currentDirectory.getParentFile());
}
} else {
File l_clickedFile = new File(this.displayEntries.get((int)id).getText());
if (l_clickedFile != null) {
if (l_clickedFile.isDirectory()) {
last_list_view_pos = 0;
browseTo(l_clickedFile);
} else {
showVideoInfo(l_clickedFile);
}
}
}
}
private void browseTo(final File _dir) {
if (_dir.isDirectory()) {
this.currentDirectory = _dir;
loadVideosFromDirectory(_dir.getAbsolutePath());
}
}
/**
* Slow adapter: this part of the code implements the list adapter
* Will not bind views while the list is scrolling
*/
private class SlowAdapter extends BaseAdapter {
/** Remember our context so we can use it when constructing views. */
private Context mContext;
private List<iconifiedtextselected> mItems = new ArrayList<iconifiedtextselected>();
public SlowAdapter(Context context) {
mContext = context;
}
public void setListItems(List<iconifiedtextselected> lit)
{ mItems = lit; }
/** @return The number of items in the */
public int getCount() { return mItems.size(); }
public Object getItem(int position)
{ return mItems.get(position); }
/** Use the array index as a unique id. */
public long getItemId(int position) {
return position;
}
/** @param convertView The old view to overwrite, if one is passed
* @returns a IconifiedTextSelectedView that holds wraps around an IconifiedText */
public View getView(int position, View convertView, ViewGroup parent) {
IconifiedTextSelectedView btv;
if (convertView == null) {
btv = new IconifiedTextSelectedView(mContext, mItems.get(position));
} else { // Reuse/Overwrite the View passed
// We are assuming(!) that it is castable!
btv = (IconifiedTextSelectedView) convertView;
btv.setText(mItems.get(position).getText());
}
if (position==0) {
if (VideoBrowser.self.media_browser_load_option==0) {
btv.setIcon(R.drawable.folderback);
} else if (mItems.get(0).getIcon()!=null) {
btv.setIcon(mItems.get(position).getIcon());
} else {
btv.setIcon(R.drawable.video);
}
}
//in busy mode
else if (mBusy){
//if icon is NULL: the icon is not loaded yet; load default icon
if (mItems.get(position).getIcon()==null) {
btv.setIcon(R.drawable.video);
//mark this view, indicates the icon is not loaded
btv.setTag(this);
} else {
//if icon is not null, just display the icon
btv.setIcon(mItems.get(position).getIcon());
//mark this view, indicates the icon is loaded
btv.setTag(null);
}
} else {
//if not busy
Drawable d = mItems.get(position).getIcon();
if (d == null) {
//icon is not loaded, load now
btv.setIcon(R.drawable.video);
btv.setTag(this);
} else {
btv.setIcon(mItems.get(position).getIcon());
btv.setTag(null);
}
}
return btv;
}
}
</iconifiedtextselected></iconifiedtextselected></iconifiedtextselected></iconifiedtextselected></iconifiedtextselected></iconifiedtextselected></iconifiedtextselected>}