Ejemplo n.º 1
0
TrackSupplier*
UrlPlaylistItem::_CreateTrackSupplier() const
{
	MediaFileTrackSupplier* supplier
		= new(std::nothrow) MediaFileTrackSupplier();
	if (supplier == NULL)
		return NULL;

	BMediaFile* mediaFile = new(std::nothrow) BMediaFile(fUrl);
	if (mediaFile == NULL || supplier->AddMediaFile(mediaFile) != B_OK) {
		delete mediaFile;
		delete supplier;
		return NULL;
	}

	return supplier;
}
Ejemplo n.º 2
0
TrackSupplier*
FilePlaylistItem::CreateTrackSupplier() const
{
	MediaFileTrackSupplier* supplier
		= new(std::nothrow) MediaFileTrackSupplier();
	if (supplier == NULL)
		return NULL;

	for (vector<entry_ref>::size_type i = 0; i < fRefs.size(); i++) {
		BMediaFile* mediaFile = new(std::nothrow) BMediaFile(&fRefs[i]);
		if (mediaFile == NULL) {
			delete supplier;
			return NULL;
		}
		if (supplier->AddMediaFile(mediaFile) != B_OK)
			delete mediaFile;
	}

	for (vector<entry_ref>::size_type i = 0; i < fImageRefs.size(); i++) {
		BBitmap* bitmap = BTranslationUtils::GetBitmap(&fImageRefs[i]);
		if (bitmap == NULL)
			continue;
		if (supplier->AddBitmap(bitmap) != B_OK)
			delete bitmap;
	}

	// Search for subtitle files in the same folder
	// TODO: Error checking
	BEntry entry(&fRefs[0], true);

	char originalName[B_FILE_NAME_LENGTH];
	entry.GetName(originalName);
	BString nameWithoutExtension(originalName);
	int32 extension = nameWithoutExtension.FindLast('.');
	if (extension > 0)
		nameWithoutExtension.Truncate(extension);

	BPath path;
	entry.GetPath(&path);
	path.GetParent(&path);
	BDirectory directory(path.Path());
	while (directory.GetNextEntry(&entry) == B_OK) {
		char name[B_FILE_NAME_LENGTH];
		if (entry.GetName(name) != B_OK)
			continue;
		BString nameString(name);
		if (nameString == originalName)
			continue;
		if (nameString.IFindFirst(nameWithoutExtension) < 0)
			continue;

		BFile file(&entry, B_READ_ONLY);
		if (file.InitCheck() != B_OK)
			continue;

		int32 pos = nameString.FindLast('.');
		if (pos < 0)
			continue;

		BString extensionString(nameString.String() + pos + 1);
		extensionString.ToLower();

		BString language = "default";
		if (pos > 1) {
			int32 end = pos;
			while (pos > 0 && *(nameString.String() + pos - 1) != '.')
				pos--;
			language.SetTo(nameString.String() + pos, end - pos);
		}

		if (extensionString == "srt") {
			SubTitles* subTitles
				= new(std::nothrow) SubTitlesSRT(&file, language.String());
			if (subTitles != NULL && !supplier->AddSubTitles(subTitles))
				delete subTitles;
		}
	}

	return supplier;
}