-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #49 from lrtlt/feature/car-play-podcasts
Feature/car play podcasts
- Loading branch information
Showing
35 changed files
with
464 additions
and
129 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
import {ListTemplate} from 'react-native-carplay'; | ||
|
||
export const carPlayCategoryTemplate = new ListTemplate({ | ||
title: 'Laida', | ||
id: 'lrt-list-template-Category', | ||
sections: [ | ||
{ | ||
items: [], | ||
}, | ||
], | ||
backButtonHidden: true, | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
import {useEffect, useState} from 'react'; | ||
import {CategoryListItem} from '../CarPlayContext'; | ||
import useCancellablePromise from '../../hooks/useCancellablePromise'; | ||
import {fetchCarCategoryPlaylist} from '../../api'; | ||
import {IMG_SIZE_XS, buildImageUri} from '../../util/ImageUtil'; | ||
|
||
const useCarPlayCategoryPlaylist = (categoryId?: number) => { | ||
const [episodes, setEpisodes] = useState<CategoryListItem[]>([]); | ||
|
||
const cancellablePromise = useCancellablePromise(); | ||
|
||
useEffect(() => { | ||
if (!categoryId) { | ||
return; | ||
} | ||
cancellablePromise( | ||
fetchCarCategoryPlaylist(categoryId).then((data) => { | ||
if (data?.articles) { | ||
const episodes: CategoryListItem[] = data.articles.map((item) => ({ | ||
articleId: item.id, | ||
text: item.title, | ||
detailText: item.item_date, | ||
imgUrl: buildImageUri(IMG_SIZE_XS, item.img_path_prefix, item.img_path_postfix), | ||
})); | ||
setEpisodes(episodes); | ||
} | ||
}), | ||
); | ||
}, [categoryId]); | ||
|
||
return { | ||
episodes, | ||
}; | ||
}; | ||
|
||
export default useCarPlayCategoryPlaylist; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,67 @@ | ||
import {useEffect, useState} from 'react'; | ||
import {CarPlay, ListTemplate} from 'react-native-carplay'; | ||
import {useMediaPlayer} from '../../components/videoComponent/context/useMediaPlayer'; | ||
import useCarPlayCategoryPlaylist from './useCarCategoryPlaylist'; | ||
import {CarPlayPodcastItem} from '../../api/Types'; | ||
import {CategoryListItem} from '../CarPlayContext'; | ||
import useCarPlayCategoryEpisodeStream from './useCarPlayCategoryEpisodeStream'; | ||
import {MediaType} from '../../components/videoComponent/context/PlayerContext'; | ||
import {carPlayNowPlayingTemplate} from '../nowPlaying/createNowPlayingTemplate'; | ||
|
||
const useCarCategoryTemplate = (podcast?: CarPlayPodcastItem) => { | ||
const [template, setTemplate] = useState<ListTemplate>(); | ||
const [selectedEpisode, setSelectedEpisode] = useState<CategoryListItem | undefined>(undefined); | ||
|
||
const {episodes} = useCarPlayCategoryPlaylist(podcast?.id); | ||
const {streamInfo} = useCarPlayCategoryEpisodeStream(selectedEpisode); | ||
|
||
const {setPlaylist} = useMediaPlayer(); | ||
|
||
useEffect(() => { | ||
const t = new ListTemplate({ | ||
title: podcast?.title, | ||
id: 'lrt-list-template-podcast-' + podcast?.id, | ||
sections: [ | ||
{ | ||
items: [ | ||
...episodes.map((item) => ({ | ||
text: item.text, | ||
detailText: item.detailText, | ||
// imgUrl: item.imgUrl as any, | ||
})), | ||
], | ||
}, | ||
], | ||
backButtonHidden: true, | ||
}); | ||
t.config.onItemSelect = async ({index}) => { | ||
console.log('onItemSelect', episodes[index]); | ||
setSelectedEpisode(episodes[index]); | ||
}; | ||
setTemplate(t); | ||
return () => { | ||
t.config.onItemSelect = undefined; | ||
}; | ||
}, [episodes]); | ||
|
||
useEffect(() => { | ||
if (!streamInfo) { | ||
return; | ||
} | ||
setPlaylist([ | ||
{ | ||
title: streamInfo.text, | ||
startTime: 0, | ||
poster: streamInfo.imgUrl, | ||
uri: streamInfo.streamUrl, | ||
mediaType: MediaType.AUDIO, | ||
isLiveStream: false, | ||
}, | ||
]); | ||
CarPlay.pushTemplate(carPlayNowPlayingTemplate, true); | ||
}, [streamInfo]); | ||
|
||
return template; | ||
}; | ||
|
||
export default useCarCategoryTemplate; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
import {useEffect, useState} from 'react'; | ||
import {CategoryListItem, PlayListItem} from '../CarPlayContext'; | ||
import useCancellablePromise from '../../hooks/useCancellablePromise'; | ||
import {fetchArticle} from '../../api'; | ||
import {isMediaArticle} from '../../api/Types'; | ||
import {IMG_SIZE_XS, buildArticleImageUri} from '../../util/ImageUtil'; | ||
|
||
const useCarPlayCategoryEpisodeStream = (episode?: CategoryListItem) => { | ||
const [streamInfo, setStreamInfo] = useState<PlayListItem>(); | ||
|
||
const cancellablePromise = useCancellablePromise(); | ||
|
||
useEffect(() => { | ||
if (!episode) { | ||
return; | ||
} | ||
cancellablePromise( | ||
fetchArticle(episode.articleId).then((data) => { | ||
const article = data?.article; | ||
if (isMediaArticle(article)) { | ||
setStreamInfo({ | ||
id: episode.articleId, | ||
text: article.title, | ||
detailText: article.date, | ||
imgUrl: buildArticleImageUri(IMG_SIZE_XS, article?.main_photo?.path) as any, | ||
streamUrl: article.stream_url, | ||
}); | ||
} | ||
}), | ||
); | ||
}, [episode]); | ||
|
||
return { | ||
streamInfo, | ||
}; | ||
}; | ||
|
||
export default useCarPlayCategoryEpisodeStream; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Oops, something went wrong.