Search in sources :

Example 1 with Streamer

use of com.amaze.filemanager.utils.SmbStreamer.Streamer in project AmazeFileManager by TeamAmaze.

the class MainFragment method launchSMB.

public static void launchSMB(final SmbFile smbFile, final long si, final Activity activity) {
    final Streamer s = Streamer.getInstance();
    new Thread() {

        public void run() {
            try {
                /*
                    List<SmbFile> subtitleFiles = new ArrayList<SmbFile>();

                    // finding subtitles
                    for (Layoutelements layoutelement : LIST_ELEMENTS) {
                        SmbFile smbFile = new SmbFile(layoutelement.getDesc());
                        if (smbFile.getName().contains(smbFile.getName())) subtitleFiles.add(smbFile);
                    }
                    */
                s.setStreamSrc(smbFile, si);
                activity.runOnUiThread(() -> {
                    try {
                        Uri uri = Uri.parse(Streamer.URL + Uri.fromFile(new File(Uri.parse(smbFile.getPath()).getPath())).getEncodedPath());
                        Intent i = new Intent(Intent.ACTION_VIEW);
                        i.setDataAndType(uri, MimeTypes.getMimeType(smbFile.getPath(), smbFile.isDirectory()));
                        PackageManager packageManager = activity.getPackageManager();
                        List<ResolveInfo> resInfos = packageManager.queryIntentActivities(i, 0);
                        if (resInfos != null && resInfos.size() > 0)
                            activity.startActivity(i);
                        else
                            Toast.makeText(activity, activity.getResources().getString(R.string.smb_launch_error), Toast.LENGTH_SHORT).show();
                    } catch (ActivityNotFoundException | SmbException e) {
                        e.printStackTrace();
                    }
                });
            } catch (Exception e) {
                e.printStackTrace();
            }
        }
    }.start();
}
Also used : Streamer(com.amaze.filemanager.utils.SmbStreamer.Streamer) PackageManager(android.content.pm.PackageManager) Intent(android.content.Intent) ArrayList(java.util.ArrayList) List(java.util.List) Uri(android.net.Uri) File(java.io.File) SmbFile(jcifs.smb.SmbFile) HybridFile(com.amaze.filemanager.filesystem.HybridFile) SmbException(jcifs.smb.SmbException) ActivityNotFoundException(android.content.ActivityNotFoundException) MalformedURLException(java.net.MalformedURLException)

Aggregations

ActivityNotFoundException (android.content.ActivityNotFoundException)1 Intent (android.content.Intent)1 PackageManager (android.content.pm.PackageManager)1 Uri (android.net.Uri)1 HybridFile (com.amaze.filemanager.filesystem.HybridFile)1 Streamer (com.amaze.filemanager.utils.SmbStreamer.Streamer)1 File (java.io.File)1 MalformedURLException (java.net.MalformedURLException)1 ArrayList (java.util.ArrayList)1 List (java.util.List)1 SmbException (jcifs.smb.SmbException)1 SmbFile (jcifs.smb.SmbFile)1