মিডিয়া আর্টওয়ার্ক প্রদর্শন করুন

মিডিয়া আইটেমগুলির জন্য আর্টওয়ার্ক অবশ্যই একটি স্থানীয় URI হিসাবে ContentResolver.SCHEME_CONTENT বা ContentResolver.SCHEME_ANDROID_RESOURCE ব্যবহার করে পাস করতে হবে। এই স্থানীয় ইউআরআইকে অবশ্যই একটি বিটম্যাপ বা অ্যাপ্লিকেশনের সংস্থানগুলিতে আঁকাযোগ্য ভেক্টরের সমাধান করতে হবে। MediaDescriptionCompat বস্তুর জন্য বিষয়বস্তু অনুক্রমের আইটেম প্রতিনিধিত্ব করে, setIconUri মাধ্যমে URI পাস করুন।

প্লেয়িং আইটেম প্রতিনিধিত্বকারী MediaMetadataCompat অবজেক্টের জন্য, putString মাধ্যমে URI পাস করতে এই কীগুলির যেকোনো একটি ব্যবহার করুন:

এই পদক্ষেপগুলি বর্ণনা করে যে কীভাবে একটি ওয়েব URI থেকে আর্ট ডাউনলোড করতে হয় এবং একটি স্থানীয় URI-এর মাধ্যমে এটি প্রকাশ করতে হয়। একটি সম্পূর্ণ উদাহরণের জন্য, ইউনিভার্সাল অ্যান্ড্রয়েড মিউজিক প্লেয়ার নমুনা অ্যাপে openFile এবং আশেপাশের পদ্ধতির বাস্তবায়ন দেখুন।

  1. ওয়েব ইউআরআই-এর সাথে সম্পর্কিত একটি content:// URI তৈরি করুন। মিডিয়া ব্রাউজার পরিষেবা এবং মিডিয়া সেশন এই কন্টেন্ট URI কে Android Auto এবং Android Automotive OS (AAOS)-এ পাস করে।

    কোটলিন

    fun Uri.asAlbumArtContentURI(): Uri {
          return Uri.Builder()
            .scheme(ContentResolver.SCHEME_CONTENT)
            .authority(CONTENT_PROVIDER_AUTHORITY)
            .appendPath(this.getPath()) // Make sure you trust the URI
            .build()
      }
    

    জাভা

    public static Uri asAlbumArtContentURI(Uri webUri) {
          return new Uri.Builder()
            .scheme(ContentResolver.SCHEME_CONTENT)
            .authority(CONTENT_PROVIDER_AUTHORITY)
            .appendPath(webUri.getPath()) // Make sure you trust the URI!
            .build();
     }
    
  2. আপনার ContentProvider.openFile এর বাস্তবায়নে, সংশ্লিষ্ট URI-এর জন্য একটি ফাইল বিদ্যমান কিনা তা পরীক্ষা করুন। যদি না হয়, ডাউনলোড করুন এবং ইমেজ ফাইল ক্যাশে. এই কোড স্নিপেট গ্লাইড ব্যবহার করে।

    কোটলিন

    override fun openFile(uri: Uri, mode: String): ParcelFileDescriptor? {
          val context = this.context ?: return null
          val file = File(context.cacheDir, uri.path)
          if (!file.exists()) {
            val remoteUri = Uri.Builder()
                .scheme("https")
                .authority("my-image-site")
                .appendPath(uri.path)
                .build()
            val cacheFile = Glide.with(context)
                .asFile()
                .load(remoteUri)
                .submit()
                .get(DOWNLOAD_TIMEOUT_SECONDS, TimeUnit.SECONDS)
    
            cacheFile.renameTo(file)
             file = cacheFile
          }
          return ParcelFileDescriptor.open(file, ParcelFileDescriptor.MODE_READ_ONLY)
     }
    

    জাভা

    @Nullable
      @Override
      public ParcelFileDescriptor openFile(@NonNull Uri uri, @NonNull String mode)
            throws FileNotFoundException {
          Context context = this.getContext();
          File file = new File(context.getCacheDir(), uri.getPath());
          if (!file.exists()) {
            Uri remoteUri = new Uri.Builder()
                .scheme("https")
                .authority("my-image-site")
                .appendPath(uri.getPath())
                .build();
            File cacheFile = Glide.with(context)
                .asFile()
                .load(remoteUri)
                .submit()
                .get(DOWNLOAD_TIMEOUT_SECONDS, TimeUnit.SECONDS);
    
            cacheFile.renameTo(file);
            file = cacheFile;
          }
          return ParcelFileDescriptor.open(file, ParcelFileDescriptor.MODE_READ_ONLY);
      }
    

বিষয়বস্তু প্রদানকারীদের সম্পর্কে বিশদ বিবরণের জন্য, একটি সামগ্রী প্রদানকারী তৈরি করুন দেখুন।

,

মিডিয়া আইটেমগুলির জন্য আর্টওয়ার্ক অবশ্যই একটি স্থানীয় URI হিসাবে ContentResolver.SCHEME_CONTENT বা ContentResolver.SCHEME_ANDROID_RESOURCE ব্যবহার করে পাস করতে হবে। এই স্থানীয় ইউআরআইকে অবশ্যই একটি বিটম্যাপ বা অ্যাপ্লিকেশনের সংস্থানগুলিতে আঁকাযোগ্য ভেক্টরের সমাধান করতে হবে। MediaDescriptionCompat বস্তুর জন্য বিষয়বস্তু অনুক্রমের আইটেম প্রতিনিধিত্ব করে, setIconUri মাধ্যমে URI পাস করুন।

প্লেয়িং আইটেম প্রতিনিধিত্বকারী MediaMetadataCompat অবজেক্টের জন্য, putString মাধ্যমে URI পাস করতে এই কীগুলির যেকোনো একটি ব্যবহার করুন:

এই পদক্ষেপগুলি বর্ণনা করে যে কীভাবে একটি ওয়েব URI থেকে আর্ট ডাউনলোড করতে হয় এবং একটি স্থানীয় URI-এর মাধ্যমে এটি প্রকাশ করতে হয়। একটি সম্পূর্ণ উদাহরণের জন্য, ইউনিভার্সাল অ্যান্ড্রয়েড মিউজিক প্লেয়ার নমুনা অ্যাপে openFile এবং আশেপাশের পদ্ধতির বাস্তবায়ন দেখুন।

  1. ওয়েব ইউআরআই-এর সাথে সম্পর্কিত একটি content:// URI তৈরি করুন। মিডিয়া ব্রাউজার পরিষেবা এবং মিডিয়া সেশন এই কন্টেন্ট URI কে Android Auto এবং Android Automotive OS (AAOS)-এ পাস করে।

    কোটলিন

    fun Uri.asAlbumArtContentURI(): Uri {
          return Uri.Builder()
            .scheme(ContentResolver.SCHEME_CONTENT)
            .authority(CONTENT_PROVIDER_AUTHORITY)
            .appendPath(this.getPath()) // Make sure you trust the URI
            .build()
      }
    

    জাভা

    public static Uri asAlbumArtContentURI(Uri webUri) {
          return new Uri.Builder()
            .scheme(ContentResolver.SCHEME_CONTENT)
            .authority(CONTENT_PROVIDER_AUTHORITY)
            .appendPath(webUri.getPath()) // Make sure you trust the URI!
            .build();
     }
    
  2. আপনার ContentProvider.openFile এর বাস্তবায়নে, সংশ্লিষ্ট URI-এর জন্য একটি ফাইল বিদ্যমান কিনা তা পরীক্ষা করুন। যদি না হয়, ডাউনলোড করুন এবং ইমেজ ফাইল ক্যাশে. এই কোড স্নিপেট গ্লাইড ব্যবহার করে।

    কোটলিন

    override fun openFile(uri: Uri, mode: String): ParcelFileDescriptor? {
          val context = this.context ?: return null
          val file = File(context.cacheDir, uri.path)
          if (!file.exists()) {
            val remoteUri = Uri.Builder()
                .scheme("https")
                .authority("my-image-site")
                .appendPath(uri.path)
                .build()
            val cacheFile = Glide.with(context)
                .asFile()
                .load(remoteUri)
                .submit()
                .get(DOWNLOAD_TIMEOUT_SECONDS, TimeUnit.SECONDS)
    
            cacheFile.renameTo(file)
             file = cacheFile
          }
          return ParcelFileDescriptor.open(file, ParcelFileDescriptor.MODE_READ_ONLY)
     }
    

    জাভা

    @Nullable
      @Override
      public ParcelFileDescriptor openFile(@NonNull Uri uri, @NonNull String mode)
            throws FileNotFoundException {
          Context context = this.getContext();
          File file = new File(context.getCacheDir(), uri.getPath());
          if (!file.exists()) {
            Uri remoteUri = new Uri.Builder()
                .scheme("https")
                .authority("my-image-site")
                .appendPath(uri.getPath())
                .build();
            File cacheFile = Glide.with(context)
                .asFile()
                .load(remoteUri)
                .submit()
                .get(DOWNLOAD_TIMEOUT_SECONDS, TimeUnit.SECONDS);
    
            cacheFile.renameTo(file);
            file = cacheFile;
          }
          return ParcelFileDescriptor.open(file, ParcelFileDescriptor.MODE_READ_ONLY);
      }
    

বিষয়বস্তু প্রদানকারীদের সম্পর্কে বিশদ বিবরণের জন্য, একটি সামগ্রী প্রদানকারী তৈরি করুন দেখুন।