[Android] Add nullity checks for Medialibrary calls
Geoffrey Métais
git at videolan.org
Mon May 29 15:33:02 CEST 2017
vlc-android | branch: master | Geoffrey Métais <geoffrey.metais at gmail.com> | Mon May 29 14:52:08 2017 +0200| [3b57c8a6d3e817111e5cac19839fabe6a45120a8] | committer: Geoffrey Métais
Add nullity checks for Medialibrary calls
> https://code.videolan.org/videolan/vlc-android/commit/3b57c8a6d3e817111e5cac19839fabe6a45120a8
---
medialibrary/jni/AndroidMediaLibrary.cpp | 37 ++++++++++++++++----------------
1 file changed, 18 insertions(+), 19 deletions(-)
diff --git a/medialibrary/jni/AndroidMediaLibrary.cpp b/medialibrary/jni/AndroidMediaLibrary.cpp
index 7e41e38bf..ebb83eebd 100644
--- a/medialibrary/jni/AndroidMediaLibrary.cpp
+++ b/medialibrary/jni/AndroidMediaLibrary.cpp
@@ -320,75 +320,74 @@ AndroidMediaLibrary::PlaylistCreate( const std::string &name )
std::vector<medialibrary::MediaPtr>
AndroidMediaLibrary::tracksFromAlbum( int64_t albumId )
{
- return p_ml->album(albumId)->tracks();
+ auto album = p_ml->album(albumId);
+ return album == nullptr ? std::vector<medialibrary::MediaPtr>() : album->tracks();
}
std::vector<medialibrary::MediaPtr>
AndroidMediaLibrary::mediaFromArtist( int64_t artistId )
{
- return p_ml->artist(artistId)->media();
+ auto artist = p_ml->artist(artistId);
+ return artist == nullptr ? std::vector<medialibrary::MediaPtr>() : artist->media();
}
std::vector<medialibrary::AlbumPtr>
AndroidMediaLibrary::albumsFromArtist( int64_t artistId )
{
- return p_ml->artist(artistId)->albums();
+ auto artist = p_ml->artist(artistId);
+ return artist == nullptr ? std::vector<medialibrary::AlbumPtr>() : artist->albums();
}
std::vector<medialibrary::MediaPtr>
AndroidMediaLibrary::mediaFromGenre( int64_t genreId )
{
- return p_ml->genre(genreId)->tracks();
+ auto genre = p_ml->genre(genreId);
+ return genre == nullptr ? std::vector<medialibrary::MediaPtr>() : genre->tracks();
}
std::vector<medialibrary::AlbumPtr>
AndroidMediaLibrary::albumsFromGenre( int64_t genreId )
{
- return p_ml->genre(genreId)->albums();
+ auto genre = p_ml->genre(genreId);
+ return genre == nullptr ? std::vector<medialibrary::AlbumPtr>() : genre->albums();
}
std::vector<medialibrary::ArtistPtr>
AndroidMediaLibrary::artistsFromGenre( int64_t genreId )
{
- return p_ml->genre(genreId)->artists();
+ auto genre = p_ml->genre(genreId);
+ return genre == nullptr ? std::vector<medialibrary::ArtistPtr>() : genre->artists();
}
std::vector<medialibrary::MediaPtr>
AndroidMediaLibrary::mediaFromPlaylist( int64_t playlistId )
{
- return p_ml->playlist(playlistId)->media();
+ auto playlist = p_ml->playlist(playlistId);
+ return playlist == nullptr ? std::vector<medialibrary::MediaPtr>() : playlist->media();
}
bool
AndroidMediaLibrary::playlistAppend(int64_t playlistId, int64_t mediaId) {
medialibrary::PlaylistPtr playlist = p_ml->playlist(playlistId);
- if (playlist == nullptr)
- return false;
- return playlist->append(mediaId);
+ return playlist == nullptr ? false : playlist->append(mediaId);
}
bool
AndroidMediaLibrary::playlistAdd(int64_t playlistId, int64_t mediaId, unsigned int position) {
medialibrary::PlaylistPtr playlist = p_ml->playlist(playlistId);
- if (playlist == nullptr)
- return false;
- return playlist->add(mediaId, position);
+ return playlist == nullptr ? false : playlist->add(mediaId, position);
}
bool
AndroidMediaLibrary::playlistMove(int64_t playlistId, int64_t mediaId, unsigned int position) {
medialibrary::PlaylistPtr playlist = p_ml->playlist(playlistId);
- if (playlist == nullptr)
- return false;
- return playlist->move(mediaId, position);
+ return playlist == nullptr ? false : playlist->move(mediaId, position);
}
bool
AndroidMediaLibrary::playlistRemove(int64_t playlistId, int64_t mediaId) {
medialibrary::PlaylistPtr playlist = p_ml->playlist(playlistId);
- if (playlist == nullptr)
- return false;
- return playlist->remove(mediaId);
+ return playlist == nullptr ? false : playlist->remove(mediaId);
}
bool
More information about the Android
mailing list