Home > Mobile >  SMB access and video playback and perfect solution
SMB access and video playback and perfect solution

Time:10-26

I collect a lot of film, did a Windows program, built a database to manage these film build labels, according to film, film type label indexes, such as migration has been want to have the program to TV set-top boxes, some time ago for android conducted an intensive research, including the SMB access how to transfer the user name and password, how to play the two key points after get the SMB technology,
One, first said the first main technical points, thanks to the selfless help this BBS, successfully conquer, few words said, speak directly usage, source,
First of all, in the engineering of libs folder into the jcifs - 1.3.14. Jar file, and then introduced the jar in the build path,
Create a new class in the engineering, tentatively named smbServer used to open the child thread, connect the SMB:

Public class smbServer {
Public NtlmPasswordAuthentication Authentication=null;

Public void getSmbConnect () {
The ExecutorService ser=Executors. NewFixedThreadPool (1);
ConnectSmbThread SMB=new ConnectSmbThread ();
Future Result=ser. Submit (SMB);
Try {
The Authentication=result. The get ();
{} catch InterruptedException (e)
//TODO Auto - generated the catch block,
e.printStackTrace();
} the catch (ExecutionException e) {
//TODO Auto - generated the catch block,
e.printStackTrace();
}
Ser. ShutdownNow ();
}

Private class ConnectSmbThread implements Callable {
Private String IP="192.168.1.101";//this is the IP address of the SMB

@ Override
Public NtlmPasswordAuthentication call () throws the Exception {
//TODO Auto - generated method stub
UniAddress mDomain=null;
Try {
MDomain=UniAddress. GetByName (IP);
{} the catch (UnknownHostException e2)
//TODO Auto - generated the catch block,
E2. PrintStackTrace ();
}

NtlmPasswordAuthentication mAuthentication=new NtlmPasswordAuthentication (IP, "user name", "password");
If (mDomain!=null)
{
Try {
SmbSession. Logon (mDomain mAuthentication);
} the catch (SmbException e) {
//TODO Auto - generated the catch block,
e.printStackTrace();
return null;
}
} else {
return null;
}
Return mAuthentication;
}

Public String getSMBFiles (String smbPath) {
SmbFile smbFolder=new SmbFile (smbPath mAuthentication);
Try {
SmbFile files.=smbFolder listFiles ();
String strFiles=new String;
for(int i=0; iStrFiles=files. The getName ();
}
} the catch (SmbException e) {
}
Return strFiles;
}
}

Establish a smbServer object in the MainActivity:
SmbServer SMB=new smbServer ();
The SMB. GetSmbConnect ();
String files. []=SMB getSMBFiles (" 192.168.1.101/");

Be SMB file after the two, how to implement, simple experience the process of struggle, have to say to want to switch to Http flows in the BBS, have said what all need not go directly, but it does not provide implementation method, also has a particularly profound, to open the streaming media service cache in the background, and also provides the source code, into a look, a fart to use, is purely a cheat money,
I finally realize method actually very simple, a words: to be able to be good,
As first source:

Intent Intent=new Intent ();
Intent. AddFlags (intent. FLAG_ACTIVITY_NEW_TASK);
Intent. SetAction (android. Content. Intent. ACTION_VIEW);
Intent. SetDataAndType (Uri. Parse (smbPath), "video/*");
startActivity(intent);

If the SMB set a password, use the following line of code
SmbPath=smbPath. Replace (" SMB://", "SMB://user name: password @");
Such as your SMB file: SMB://192.168.1.101/ABC/efg MPG
Through on the same line of code becomes: SMB://user name: password @ 192.168.1.101/ABC/efg MPG

Implicit open Activity need external App can response, this App is VLC, this function can be achieved after installed the VLC,
But in the use process found that some would be able to open the play, some complains, after many groping, found that as long as the VLC Settings, no error,
VLC Settings method: open the VLC, enter the "Settings" page, find the "advanced" option, in the "Internet cache" set to random values,
  • Related